strip-comments icon indicating copy to clipboard operation
strip-comments copied to clipboard

[BUG] URL Bug

Open da411d opened this issue 5 years ago • 6 comments

strip("let something = 'https://example.com';");

Expected output:

let something = 'https://example.com';

Fact output:

let something = 'https:

da411d avatar Dec 10 '19 13:12 da411d

I have the same problem.

viktorvi avatar Dec 25 '19 13:12 viktorvi

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.

hobbes7878 avatar Jan 31 '20 20:01 hobbes7878

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

billylittlefield avatar Feb 07 '20 18:02 billylittlefield

I am experiencing this issue as well. It's a dealbreaker for me

camiblanch avatar Jun 19 '20 17:06 camiblanch

Are they still going to fix this?

getrebuild avatar May 15 '22 10:05 getrebuild

Are they still going to fix this?

This repo is solved https://github.com/freeCodeCamp/strip-comments

getrebuild avatar May 15 '22 10:05 getrebuild