Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default function matches(str, pattern, modifiers) {
if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
pattern = new RegExp(pattern, modifiers);
}
return pattern.test(str);
return !!str.match(pattern);
Copy link
Contributor Author

@fedeci fedeci May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.test keeps the state when used along with a regex that has the global or the sticky flag. We can prevent that behaviour getting stateless validation using .match

/cc @tux-tn @ezkemboi

Copy link

@tonysamperi tonysamperi May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using Array.isArray(str.match(pattern)) or str.match(pattern) !== null since the possible return values of .matches are Array or null?
The result is obviously the same, but semantically seems more appropriate to me :)
And maybe they'll be more inclined to accept the PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly find that excessively verbose and probably won't be a blocker for the pr. Let's see what the maintainers think.

}