Regex RangeError for large sourcemaps
See original GitHub issueHi. We’re using webpack’s devtool: #cheap-module-inline-source-map
option to add an inline base64 encoded source map to the bottom of our main app file. There’s a decent amount of code there, so the sourcemap is a pretty gigantic string.
We ended up seeing the following error in the console:
RangeError: Maximum call stack size exceeded
at RegExp.exec (native)
Related to this regex:
var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
Changing one character in the regex fixes the issue (...[^\s'"]+?...
to ...[^\s'"]*?...
):
var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]*?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
I haven’t been able to figure out why that is yet though (e.g. I don’t think there’s any catastrophic backtracking going on in the original version?) 😕
Just wondering if anyone else can shed some light on this? Cheers. (PS this change also works for the version currently published to npm).
Issue Analytics
- State:
- Created 8 years ago
- Comments:7
Top Results From Across the Web
3878 - RangeError running RegExp on large string - Monorail
This is working as intended. This particular regular expression requires backtracking. This means that values have to be pushed onto a stack, ...
Read more >How to improve regex for removing source map URLs in js ...
It fails with PREG_BACKTRACK_LIMIT_ERROR = Catastrophic backtracking when the source map url is a large //# sourceMappingURL=data:application/ ...
Read more >Writing a regex to detect a range of numbers? Why not just ...
The Regex Puzzle The simplest way to solve this problem is to convert the numerical range into a regex value with every single...
Read more >Node.js v19.3.0 Documentation
If specified, error can be a Class , RegExp , a validation function, a validation object where each property will be tested for...
Read more >Regular expression syntax cheatsheet - JavaScript | MDN
Disjunctions are not atoms — you need to use a group to make it part of a bigger pattern. [abc] is functionally equivalent...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be fixed in version
0.5.13
, please report back if the issue persists!This issue is still present. Are there any plans for fixing this?
Here’s more detailed stacktrace, if it helps: