Skip to content

Commit

Permalink
fix: string.matches() and regex global flag (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
vonagam authored and jquense committed Apr 23, 2019
1 parent 1c18442 commit a8935b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inherits(StringSchema, MixedSchema, {
test: value =>
isAbsent(value) ||
(value === '' && excludeEmptyString) ||
regex.test(value),
value.search(regex) !== -1,
});
},

Expand Down
15 changes: 15 additions & 0 deletions test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ describe('String types', () => {
]);
});

it('should check MATCHES correctly with global and sticky flags', function() {
var v = string().matches(/hi/gy);

return Promise.all([
v
.isValid('hi')
.should.eventually()
.equal(true),
v
.isValid('hi')
.should.eventually()
.equal(true),
]);
});

it('MATCHES should include empty strings', () => {
let v = string().matches(/(hi|bye)/);

Expand Down

0 comments on commit a8935b7

Please sign in to comment.