Skip to content

Regex RangeError for large sourcemaps #93

Closed
@tanem

Description

@tanem

Hi. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions