tedious / JShrink

Javascript Minifier built in PHP
http://www.tedivm.com
BSD 3-Clause "New" or "Revised" License
749 stars 152 forks source link

Double slash inside of string being detected as comment #102

Closed zanysoft closed 1 year ago

zanysoft commented 3 years ago

In code i returning a url "https://player.vimeo.com/api/player.js"

getApiURL(){return "https://player.vimeo.com/api/player.js"}}

but after minifying code is removed after "https:" because you code consider a url as comment after double slash. code after minified: getApiURL(){return "https:;

kodalee commented 1 year ago

It seems this is no longer an issue but I might be wrong, here was my implementation and results from using code you had supplied.

Ignore the $scripts->get stuff, this was my usage, for the page I tested it on, I used your code

$scriptContent = Minifier::minify($scripts->get($page->scripts, [
     "global_access" => false,
     "cross_var" => true
]), array('flaggedComments' => false));

Code in JavaScript:

var test = {getApiURL(){return "https://player.vimeo.com/api/player.js"}};
console.log(test.getApiURL());

I was able to get the issues code without issues.

{
    "pageHtml": "<h1>test script stuff</h1>",
    "script": ["var test={getApiURL(){return\"https:\/\/player.vimeo.com\/api\/player.js\"}}\nconsole.log(test.getApiURL())"]
}

The code was executed and came out like such: image

kodalee commented 1 year ago

Oh boy I'm an idiot, I glanced at the date and thought it was Jan 11, 2023 and not 2021 🤦‍♂️

tedivm commented 1 year ago

I can't reproduce this so I'm closing it, but if you can come up with a test case with the current version of jshrink please let me know!