Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

fix: do not match too many characters when removing sourceMappingURL … #286

Merged
merged 4 commits into from Sep 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.js
Expand Up @@ -87,7 +87,7 @@ ${
}

// Matches only the last occurrence of sourceMappingURL
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*([^\s'"]*)\s*/;
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*((?:[^\s'"\\]|\\[^n])*(?:\\n)?)\s*/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^n? Looks it is invalid

Copy link
Contributor Author

@schl3ck schl3ck Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to match everything except all whitespace, quotes and \n literally (not the line feed character), but not a backslash on its own. It works like a negative lookahead but consuming characters. Another possible solution would be .*?(?=[\s'"]|\\n)(?:\\n)?, which actually looks a lot more readable (instead of (?:[^\s'"\\]|\\[^n])*(?:\\n)?)

And I've just noticed that with the current regex the match wouldn't stop when it encounters a whitespace or quote after a backslash, but it would have done before. Also the test will fail, if it is in a multiline comment. I will work on a fix. Thanks for not letting this slip past!


/* eslint-disable prefer-template */
const sourceMappingURLRegex = RegExp(
Expand Down