ndparker / rjsmin

Fast javascript minifier for Python
http://opensource.perlig.de/rjsmin/
Apache License 2.0
60 stars 15 forks source link

[Bug] // in base64 encoded string is removed as it's considered a comment. #27

Open hatemelseidy opened 1 year ago

hatemelseidy commented 1 year ago

My javascript contains a line that looks like this

consts: [[1, "container"], [1, "title"], [1, "code"], [1, "arg"], [1, "exhibits-container"], [1, "exhibit"], [1, "screenshot"], ["src", "data:image/png;base64,iVBO......//KyXm3KAwxw2QNQQhqQN8FSX/noEbGW5WA...]],

Trying to minify but I kept getting a syntax error Uncaught SyntaxError: Invalid or unexpected token After some investigation I noticed that a base64 encoded string of an image contained //. And in the minified version, everything after the first appearance of // is missing.

ndparker commented 1 year ago

Hi,

Thanks for your report.

However, your example basically works as expected (I've added a double quote at the end of the base64 string):

python -mrjsmin <<<'consts: [[1, "container"], [1, "title"], [1, "code"], [1, "arg"], [1, "exhibits-container"], [1, "exhibit"], [1, "screenshot"], ["src", "data:image/png;base64,iVBO......//KyXm3KAwxw2QNQQhqQN8FSX/noEbGW5WA..."]],'

Output:

consts:[[1,"container"],[1,"title"],[1,"code"],[1,"arg"],[1,"exhibits-container"],[1,"exhibit"],[1,"screenshot"],["src","data:image/png;base64,iVBO......//KyXm3KAwxw2QNQQhqQN8FSX/noEbGW5WA..."]],

I suspect, it's running out of sync before - i.e. there's a missing double quote somewhere. Could you provide a reproducible example?

Thanks,

hatemelseidy commented 1 year ago

Thanks for getting back on this. It could be a bug in my setup, will try it on isolation and update the issue.