Pattern handling breaks when passing patterns with flags #325
Labels
enhancement
feedback
Waiting for more information from OP. May be closed after 2 weeks with no response.
Milestone
Recently updated to 1.3.0, the bug seems to have been introduced in 1.2.7 relating to commit 35db08d (thanks to issue #311 for finding this for me) confirmed still present in 1.4.0
The issue is that when passing an existing regex pattern
/abc/i
(matches 'abc', 'ABC' and various combinations) the existing flags are overridden by the addition of the 'u' flag making the resulting pattern/abc/u
(matches ONLY 'abc'). By using thenew RegExp(pattern, flags)
constructor the flags parameter when provided overrides all existing flags if the pattern has any.In my opinion forcing the
u
flag on all regex is wrong, if that is the default when passing as string patterns I don't see anything strictly wrong with that, but if I pass a pattern why are my flags being messed with? If adding the u flag is for some reason required even when I didn't set it myself my flags should at least be preserved.The following would be my preferred solution
If forcing the
u
flag is deemed necessary then substitutingregexp = new RegExp(pattern, pattern.flags + 'u');
should work for the passing a regex object caseThe text was updated successfully, but these errors were encountered: