-
-
Notifications
You must be signed in to change notification settings - Fork 273
fix: do not match too many characters when removing sourceMappingURL … #286
Conversation
…comment a sourceMappingURL comment may be created by another loader and this removes it again, but too many characters are removed, thus uncommenting a different line that contains invalid javascript Closes #285
Codecov Report
@@ Coverage Diff @@
## master #286 +/- ##
=======================================
Coverage 74.48% 74.48%
=======================================
Files 6 6
Lines 145 145
Branches 52 52
=======================================
Hits 108 108
Misses 31 31
Partials 6 6
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add tests?
src/utils.js
Outdated
@@ -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*/; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
…lashes when it shouldn't The regex is also much more readable
Fix failing test when `sourceURL=webpack-internal:///...` is inside a multiline comment
I don't know why the lint job fails. I've tested it at the |
@schl3ck All fine, don't worry, I will look at this in near future |
…comment
a sourceMappingURL comment may be created by another loader and this removes it again, but too many
characters are removed, thus uncommenting a different line that contains invalid javascript
Closes #285
This PR contains a:
Motivation / Use-Case
See #285