Skip to content

Commit

Permalink
[fixed] default in concat()
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Sep 9, 2016
1 parent bb5b8a5 commit be80413
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,36 @@ function StringSchema() {
}
});
},
matches: function matches(regex, msg) {
var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
matches: function matches(regex) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

var _ref$excludeEmptyStri = _ref.excludeEmptyString;
var excludeEmptyString = _ref$excludeEmptyStri === undefined ? true : _ref$excludeEmptyStri;
var excludeEmptyString = false,
message = void 0;

if (options.message || options.hasOwnProperty('excludeEmptyString')) {
excludeEmptyString = options.excludeEmptyString;
message = options.message;
} else message = options;

return this.test({
message: msg || _locale.string.matches,
message: message || _locale.string.matches,
params: { regex: regex },
test: function test(value) {
return (0, _isAbsent2.default)(value) || value === '' && excludeEmptyString || regex.test(value);
}
});
},
email: function email(msg) {
return this.matches(rEmail, msg || _locale.string.email);
return this.matches(rEmail, {
message: msg || _locale.string.email,
excludeEmptyString: true
});
},
url: function url(msg) {
return this.matches(rUrl, msg || _locale.string.url);
return this.matches(rUrl, {
message: msg || _locale.string.url,
excludeEmptyString: true
});
},


Expand Down
2 changes: 1 addition & 1 deletion src/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ SchemaType.prototype = {
var next = merge(this.clone(), schema.clone())

// undefined isn't merged over, but is a valid value for default
if (schema._default === undefined && has(this, '_default'))
if (has(schema, '_default'))
next._default = schema._default

next.tests = cloned.tests;
Expand Down

0 comments on commit be80413

Please sign in to comment.