Invalid regular expression: /\${[^}]+}/: Incomplete quantifier
coderaiser opened this issue · 6 comments
After optimization: /\$\{[^}]+\}/u
-> /\${[^}]+}/u
, I have Invalid regular expression
error:
const regex1 = /\$\{[^}]+\}/u
const regex2 = /\${[^}]+}/u;
VM356:1 Uncaught SyntaxError: Invalid regular expression: /\${[^}]+}/: Incomplete quantifier
at <anonymous>:1:16
(anonymous) @ VM356:1
Same with:
/{{([^{}]+?)}}/gu
->/\{\{([^{}]+?)\}\}/gu
:Lone quantifier brackets
/\$\{$/u
->/\${$/u
:Incomplete quantifier
/^\/([^\\[]|\\.|\[([^\\\]]|\\.)+\])*\/[gimuys]*$/u
->/^\/([^[\\]|\\.|\[([^\\\]]|\\.)+])*\/[gimsuy]*$/u
:Unterminated group
/\$\{[^}]+\}/u
->/\${[^}]+}/u
:Incomplete quantifier
/\\(\$\{|\r\n?|\n|.)|["']|\$\{|(\r\n?|\n)/gu
->/\\(\${|\r\n?|\n|.)|["']|\${|(\r\n?|\n)/gu
:Incomplete quantifier
Thanks for reporting. Yes, this relates to the /u
flag specifically, without it it's a valid regexp. Will take a look at this later and will appreciate a PR if you reach it earlier.
I blacklisted charEscapeUnescape
, and everything works good. I have a question about using optimize
, I ended up with:
const whitelist = [];
regexpTree.optimize(regexp, whitelist, {
blacklist: [
'charEscapeUnescape',
]
});
And whitelist
cannot be null
, because there is a length
check, so this is mandatory
field.
Is it correct API
? Why don't you use:
const whitelist = [];
regexpTree.optimize(regexp, {
whitelist: [], //optional
blacklist: [], // optional
});
Like described in API.
Looks like it is related to #162
@coderaiser interesting, seems the wrapper for optimize
wasn't updated to accept the object instead.
Feel free to send a PR for this, although we should make sure to support backward compatibility here, so you can check for the type of the whitelist
parameter. Something like:
optimize(regexp, whitelist = [], {blacklist} = {}) {
// Legacy API:
if (Array.isArray(whitelist)) {
return optimizer.optimize(regexp, {whitelist, blacklist});
}
// Otherwise the `whitelist` is an object containing needed lists:
({whitelist, blacklist} = whitelist);
return optimizer.optimize(regexp, {whitelist, blacklist});
},
One more minimal reproduction:
/\]/u
-> /]/u
: Lone quantifier brackets
@EvgenyOrekhov thanks for the extra example. I won't appreciate a PR fixing this issue if you'd like to come up with one.