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

Newlines in evaluated RegExp literals are not escaped #3434

Closed
RunDevelopment opened this issue Jul 14, 2019 · 3 comments · Fixed by #3453
Closed

Newlines in evaluated RegExp literals are not escaped #3434

RunDevelopment opened this issue Jul 14, 2019 · 3 comments · Fixed by #3453

Comments

@RunDevelopment
Copy link

Bug report

When compression code of the form RegExp("any string literal"), new lines are not escaped resulting is syntactically incorrect code.

Version
uglify-js 3.6.0

Complete minify() options

{
	compress: {
		unsafe: true
	}
}

uglify-js input

console.log(RegExp("\\\nfo\n[\n]o\\bbb"));

uglify-js output

console.log(/\
fo
[
]o\bbb/);

Expected result

console.log(/\nfo\n[\n]o\bbb/);

Note: This is the same bug as this one.

@alexlamsl
Copy link
Collaborator

Very peculiar indeed - and since it's consistent across all Node.js versions (0.10 and above), I guess we'll need to work around this.

@RunDevelopment
Copy link
Author

I actually wrote a fix for this for Terser. This is the main function.

Anyone feel free to make a PR/commit with the function in it.

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Oct 6, 2019
@alexlamsl
Copy link
Collaborator

Thanks for the heads up - I've borrowed your test case in #3453

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.

2 participants