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

Nodejs spends a lot of time when using replace and regular expression replacement. #52468

Closed
FuHongBiao opened this issue Apr 11, 2024 · 2 comments

Comments

@FuHongBiao
Copy link

FuHongBiao commented Apr 11, 2024

Version

v21.1.0

Platform

windows & linux

Subsystem

replace

What steps will reproduce the bug?

let str = `<a name=\"_Changes\"></a><font face=\"Calibri, seri`
const res = str.replace(reg, '<div id="$1" style="visibility: none;"></div>');
console.log(res);

For such a simple string, str.replace takes nearly 1 minute.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

image
image

Additional information

No response

@VoltrexKeyva
Copy link
Member

This has nothing to do with Node.js, your regular expression causes catastrophic backtracking across almost every regex engine out there.

See this test and an explanation of runaway regular expressions.

If you also launch the debugger in that test you'll see almost 120k steps being walked through because of that backtracking.

@benjamingr
Copy link
Member

Additionally, js engine bugs should be reported to V8 directly and not us, we can't fix them here anyway :)

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

No branches or pull requests

3 participants