jalmenarez / minify

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

Empty string returned (Regular Expression has PREG_BACKTRACK_LIMIT_ERROR) #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of Minify are you using? PHP version?
2.0.1

What steps will reproduce the problem?
1. pcre.backtrack_limit set in the php.ini to the default (100,000 I think).
2. A single line in the HTML needs to be longer than 50773 characters.
3. Minify the HTML.

What is the expected output?
Some HTML.

What do you see instead?
Empty string.

Please provide any additional information below.

The problem is caused by a long line (> 50773 characters) having too many
backtracks in a Regular Expression.

In Minify/HTML.php the problem line is:

$html = preg_replace('/^\\s*(.*?)\\s*$/m','$1', $html);

I think the .* is causing too many bracktracks. To solve this, I changed
this line to:

$html = preg_replace('/^\\s*([^\s]*?)\\s*$/m','$1', $html);

I am not to sure on what this line is trying to achieve, but this solved my
problem.

Original issue reported on code.google.com by ecr...@gmail.com on 28 Jul 2008 at 12:08

GoogleCodeExporter commented 9 years ago
Thanks for catching this. I'm all for optimizing (or removing) regexs if 
possible. 
In this case your fix won't have the same functionality (basically a trim of 
each 
line). Can you try replacing with these lines instead?

$html = preg_replace('/^\\s*/m', '', $html);
$html = preg_replace('/\\s*$/m', '', $html);

Original comment by mrclay....@gmail.com on 28 Jul 2008 at 4:35

GoogleCodeExporter commented 9 years ago
Fixed in R160. ecroyd, can you verify this worked? I combined the patterns 
suggested 
above:

$html = preg_replace('/^\\s+|\\s+$/m', '', $html);

Original comment by mrclay....@gmail.com on 29 Jul 2008 at 4:20

GoogleCodeExporter commented 9 years ago
Both your latest solution (comment 2) and your earlier solution (comment 1) fix 
my
problem.

Thank you very much for providing such a great tool.

Original comment by ecr...@gmail.com on 29 Jul 2008 at 8:34

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 29 Jul 2008 at 11:54