strip-comments
strip-comments copied to clipboard
[BUG] URL Bug
strip("let something = 'https://example.com';");
Expected output:
let something = 'https://example.com';
Fact output:
let something = 'https:
I have the same problem.
Same. The parser isn't recognizing when forward slashes are quoted.
Kind of a big issue. For example, using this in a custom webpack loader and this line in jquery...
s.url = ( ( url || s.url || location.href ) + "" )
.replace( rprotocol, location.protocol + "//" );
... is getting mangled to ...
s.url = ( ( url || s.url || location.href ) + "" )
.replace( rprotocol, location.protocol + "
... which makes the code un-executable.
I'm currently vetting this repo and to see how it handles edge cases and trying to get a better understanding of how it works.
strip("let something = 'https://example.com';");
Expected output:
let something = 'https://example.com';
Actual output:let something = 'https:
^ I actually don't experience this behavior, are you using the most recent release?
s.url = ( ( url || s.url || location.href ) + "" ) .replace( rprotocol, location.protocol + "//" );
^ This one is interesting, . I looked into it and found that the bug actually is related to the empty string on the first line. This regex is looking for one or more characters between quote characters, so an empty string (with zero characters) results in a weird edge case. It thinks the innards of that quote are everything leading up to the first quote in the "//"
, so it doesn't register the double slash as being a quoted piece of text.
It seems to be fixed if you change that regex to use
^(['"`])((?:\\.|[^\1])*?)(\1)
(changes the '+' to a '*' to capture zero or more instead of one or more. I'm unsure if this has negative implications in other places, but it seems like a safe change (at least for javascript comment stripping).
I am experiencing this issue as well. It's a dealbreaker for me
Are they still going to fix this?
Are they still going to fix this?
This repo is solved https://github.com/freeCodeCamp/strip-comments