mirror of
https://github.com/mrclay/minify.git
synced 2025-08-21 13:21:59 +02:00
Fixes #53 (github) handles division following line break
This commit is contained in:
@@ -268,11 +268,11 @@ class JSMin {
|
||||
*/
|
||||
protected function isRegexpLiteral()
|
||||
{
|
||||
if (false !== strpos("(,=:[!&|?+-~*\n{", $this->a)) {
|
||||
if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
|
||||
// we obviously aren't dividing
|
||||
return true;
|
||||
}
|
||||
if (' ' === $this->a) {
|
||||
if ($this->a === ' ' || $this->a === "\n") {
|
||||
$length = strlen($this->output);
|
||||
if ($length < 2) { // weird edge case
|
||||
return true;
|
||||
|
@@ -1,5 +1,3 @@
|
||||
!function(){}(window)
|
||||
|
||||
!function(){}(window)
|
||||
|
||||
x = / [/] /;
|
||||
!function(){}(window)
|
@@ -1,3 +1,2 @@
|
||||
!function(){}(window)
|
||||
!function(){}(window)
|
||||
x=/ [/] /;
|
||||
!function(){}(window)
|
@@ -1,4 +0,0 @@
|
||||
|
||||
function testIssue74() {
|
||||
return /'/;
|
||||
}
|
1
min_unit_tests/_test_files/js/issue74.min.js
vendored
1
min_unit_tests/_test_files/js/issue74.min.js
vendored
@@ -1 +0,0 @@
|
||||
function testIssue74(){return /'/;}
|
@@ -1 +0,0 @@
|
||||
function testIssue74(){return /'/}
|
20
min_unit_tests/_test_files/js/regexes.js
Normal file
20
min_unit_tests/_test_files/js/regexes.js
Normal file
@@ -0,0 +1,20 @@
|
||||
function testIssue74() {
|
||||
return /'/;
|
||||
}
|
||||
|
||||
!function(s) {
|
||||
return /^[£$€?.]/.test(s);
|
||||
}();
|
||||
|
||||
typeof
|
||||
/ ' /;
|
||||
|
||||
x = / [/] /;
|
||||
|
||||
1
|
||||
|
||||
/ foo;
|
||||
|
||||
(2)
|
||||
|
||||
/ foo;
|
3
min_unit_tests/_test_files/js/regexes.min.js
vendored
Normal file
3
min_unit_tests/_test_files/js/regexes.min.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function testIssue74(){return /'/;}
|
||||
!function(s){return /^[£$€?.]/.test(s);}();typeof
|
||||
/ ' /;x=/ [/] /;1/foo;(2)/foo;
|
@@ -47,10 +47,10 @@ function test_JSMin()
|
||||
}
|
||||
}
|
||||
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js');
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/regexes.js');
|
||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/regexes.min.js');
|
||||
$minOutput = JSMin::minify($src);
|
||||
assertTrue($minExpected == $minOutput, 'JSMin : Quotes in RegExp literals (Issue 74)');
|
||||
assertTrue($minExpected == $minOutput, 'JSMin : Identify RegExp literals');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
|
Reference in New Issue
Block a user