Skip to content

Commit be80413

Browse files
committed
[fixed] default in concat()
1 parent bb5b8a5 commit be80413

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/string.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,36 @@ function StringSchema() {
7777
}
7878
});
7979
},
80-
matches: function matches(regex, msg) {
81-
var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
80+
matches: function matches(regex) {
81+
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
8282

83-
var _ref$excludeEmptyStri = _ref.excludeEmptyString;
84-
var excludeEmptyString = _ref$excludeEmptyStri === undefined ? true : _ref$excludeEmptyStri;
83+
var excludeEmptyString = false,
84+
message = void 0;
85+
86+
if (options.message || options.hasOwnProperty('excludeEmptyString')) {
87+
excludeEmptyString = options.excludeEmptyString;
88+
message = options.message;
89+
} else message = options;
8590

8691
return this.test({
87-
message: msg || _locale.string.matches,
92+
message: message || _locale.string.matches,
8893
params: { regex: regex },
8994
test: function test(value) {
9095
return (0, _isAbsent2.default)(value) || value === '' && excludeEmptyString || regex.test(value);
9196
}
9297
});
9398
},
9499
email: function email(msg) {
95-
return this.matches(rEmail, msg || _locale.string.email);
100+
return this.matches(rEmail, {
101+
message: msg || _locale.string.email,
102+
excludeEmptyString: true
103+
});
96104
},
97105
url: function url(msg) {
98-
return this.matches(rUrl, msg || _locale.string.url);
106+
return this.matches(rUrl, {
107+
message: msg || _locale.string.url,
108+
excludeEmptyString: true
109+
});
99110
},
100111

101112

src/mixed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ SchemaType.prototype = {
100100
var next = merge(this.clone(), schema.clone())
101101

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

106106
next.tests = cloned.tests;

0 commit comments

Comments
 (0)