jalmenarez / minify

Automatically exported from code.google.com/p/minify
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Debug block comments fail if /* or */ are in string constants or regular expressions #55

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Minify version: 2.1.0
PHP version: 5.2.5

What steps will reproduce the problem?
1. Use Minify::serve() with debug=true.
2. Use "*/*" in the served JavaScript.
3. Request the page.

Expected output:
A script that works just like the original.

Actual output:
Instead of /* 23 */ it says /* 23 *| in the next line just like it would
have been a block comment.

Did you run the unit tests? Did any FAIL?
No, I didn't.

Please provide any additional information below.
Should be more than enough info :).. I really like Minify btw..

Original issue reported on code.google.com by Jan.Hend...@googlemail.com on 3 Oct 2008 at 9:55

GoogleCodeExporter commented 9 years ago
From docblock: "This uses a very basic parser easily fooled by comment tokens 
inside 
strings or regexes" i.e. this is a known limitation. Fixing this for JS would 
require a rewrite based on JSMin (preserve all characters, add comments) and 
similarly for CSS using a full CSS syntax parser. Sound like fun?

In the case of JS string I think you can work around this with escapes, i.e. 
"*\/
\*". Regexps might be harder :(

Original comment by mrclay....@gmail.com on 3 Oct 2008 at 11:00

GoogleCodeExporter commented 9 years ago
I agree that this is nasty and probably not worth fixing. I just don't like 
local
changes in libraries like jQuery but I can live with them.

Original comment by Jan.Hend...@googlemail.com on 4 Oct 2008 at 12:01

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 7 Oct 2008 at 3:34

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Here's a simple patch to stop debug mode inserting errors, instead it will trim 
and 
combine files rather than add the line # comments:

On line 389 of /min/lib/Minify.php:
http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/lib/
Minify.php#389

change:

$source->minifier = array('Minify_Lines', 'minify');

to:

$source->minifier = 'trim';

Original comment by mrclay....@gmail.com on 26 Nov 2008 at 2:39

GoogleCodeExporter commented 9 years ago
Issue 71 has been merged into this issue.

Original comment by mrclay....@gmail.com on 26 Nov 2008 at 2:42

GoogleCodeExporter commented 9 years ago
If you replace the line in Lines.php:

$inComment = ! $inComment;

with:

if($pos==0 || ($inComment? substr($line, $pos, 3) : substr($line, $pos-1, 
3))!='*/*')
    $inComment = ! $inComment;

It's not perfect but at least minify will work with jquery, and I can't think 
of any
valid code that would use */*

Original comment by AdamAd...@gmail.com on 10 Dec 2008 at 2:23

GoogleCodeExporter commented 9 years ago
Awesome. Short of rewriting the Lines controller to be a complete JS parser, 
this is 
a good workaround for a common case. I'll check the unit tests and commit when 
I'm 
back in town. Thanks!

Original comment by mrclay....@gmail.com on 10 Dec 2008 at 2:48

GoogleCodeExporter commented 9 years ago
Fixed in R275

Original comment by mrclay....@gmail.com on 16 Dec 2008 at 5:15

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 16 Dec 2008 at 5:19

GoogleCodeExporter commented 9 years ago
Issue 77 has been merged into this issue.

Original comment by mrclay....@gmail.com on 21 Jan 2009 at 12:15