Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParserException: InvalidRegularExpression on valid regex #146

Closed
MaceWindu opened this issue Feb 11, 2021 · 5 comments · Fixed by #168
Closed

ParserException: InvalidRegularExpression on valid regex #146

MaceWindu opened this issue Feb 11, 2021 · 5 comments · Fixed by #168

Comments

@MaceWindu
Copy link

Regular expression literal:

/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g

Source @babel\parser\lib\index.js

const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;  

index.zip

@MaceWindu
Copy link
Author

Another case:

var match = text.match(/^(\s*)([^]*\S)(\s*)$/); 

postcss-safe-parser\lib\safe-parser.js
safe-parser.zip

@MaceWindu
Copy link
Author

var regex = /{[^]*/gm,

specificity\specificity.js
specificity.zip

@MaceWindu
Copy link
Author

const pathToArgumentName = input => {
		return input
			.replace(/\./g, "-")
			.replace(/\[\]/g, "")
			.replace(
				/(\p{Uppercase_Letter}+|\p{Lowercase_Letter}|\d)(\p{Uppercase_Letter}+)/gu,
				"$1-$2"
			)
			.replace(/-?[^\p{Uppercase_Letter}\p{Lowercase_Letter}\d]+/gu, "-")
			.toLowerCase();
	}; 

webpack\lib\cli.js
cli.zip

@jimbo118
Copy link

jimbo118 commented Jun 14, 2021

I also ran into this:

var parser = new Esprima.JavaScriptParser(@"var O = /[^]*? (:[rp] [el] a[\w -]+)[^]*/");
var program = parser.ParseScript();

Throw:

ParserException: Line 1: Invalid regular expression
Esprima.Scanner.ThrowUnexpectedToken (System.String message) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.Scanner.TestRegExp (System.String pattern, System.String flags) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.Scanner.ScanRegExp () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.NextRegexToken () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParsePrimaryExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.InheritCoverGrammar[T] (System.Func`1[TResult] parseFunction) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseLeftHandSideExpressionAllowCall () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.InheritCoverGrammar[T] (System.Func`1[TResult] parseFunction) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseUpdateExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseUnaryExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.InheritCoverGrammar[T] (System.Func`1[TResult] parseFunction) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseExponentiationExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.InheritCoverGrammar[T] (System.Func`1[TResult] parseFunction) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseBinaryExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.InheritCoverGrammar[T] (System.Func`1[TResult] parseFunction) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseConditionalExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseAssignmentExpression () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.IsolateCoverGrammar[T] (System.Func`1[TResult] parseFunction) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseVariableDeclaration (System.Boolean& inFor) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseVariableDeclarationList (System.Boolean& inFor) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseVariableStatement () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseStatement () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseStatementListItem () (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)
Esprima.JavaScriptParser.ParseScript (System.Boolean strict) (at <8417cb4e01e54c02aaa0c58a3fa07237>:0)

But it's valid on the Esprima online parserpage:

Esprima Online Parser

@sebastienros
Copy link
Owner

I was able to isolate the issue for all these reports to /[^]/. Working on the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants