From be80413635af1780f46a89bbe5e0c443960cb873 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Fri, 9 Sep 2016 12:51:53 -0400 Subject: [PATCH] [fixed] default in concat() --- lib/string.js | 25 ++++++++++++++++++------- src/mixed.js | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/string.js b/lib/string.js index 9df0009de..3349d1f37 100644 --- a/lib/string.js +++ b/lib/string.js @@ -77,14 +77,19 @@ 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); @@ -92,10 +97,16 @@ function StringSchema() { }); }, 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 + }); }, diff --git a/src/mixed.js b/src/mixed.js index 6770cbc51..22b3198d2 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -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;