diff --git a/src/JS.php b/src/JS.php index 59e0da8..ea80026 100644 --- a/src/JS.php +++ b/src/JS.php @@ -205,25 +205,27 @@ protected function extractRegex() $callback = function ($match) use ($minifier) { $count = count($minifier->extracted); $placeholder = '/'.$count.'/'; - $minifier->extracted[$placeholder] = $match[1]; + $minifier->extracted[$placeholder] = $match[0]; return $placeholder; }; - // it's a regex if we can find an opening and (not escaped) closing /, - // include \n because it may be there for a reason + $pattern = '\/.*?(?registerPattern('/'.$pattern.'\s*(?=('.$after.'|'.$methods.'))/', $callback); + + // 1 more edgecase: a regex can be followed by a lot more operators or + // keywords if there's a newline (ASI) in between, where the operator + // actually starts a new statement // (https://github.com/matthiasmullie/minify/issues/56) - $pattern = '(\/.*?(?registerPattern('/^\s*\K'.$pattern.'/', $callback); - // * following another operator, it's not division, but regex $operators = $this->getOperatorsForRegex($this->operatorsBefore, '/'); - $operators += $this->getKeywordsForRegex($this->keywordsReserved, '/'); - $this->registerPattern('/(?:'.implode('|', $operators).')\s*\K'.$pattern.'/', $callback); + $operators += $this->getOperatorsForRegex($this->keywordsReserved, '/'); + $this->registerPattern('/'.$pattern.'\s*\n?(?=\s*('.implode('|', $operators).'))/', $callback); } /** diff --git a/tests/js/JSTest.php b/tests/js/JSTest.php index 04ddfbf..7b41161 100644 --- a/tests/js/JSTest.php +++ b/tests/js/JSTest.php @@ -88,6 +88,10 @@ public function dataProvider() 'a = b / c; d = e / f', 'a=b/c;d=e/f', ); + $tests[] = array( + '(2 + 4) / 3 + 5 / 1', + '(2+4)/3+5/1', + ); $tests[] = array( 'a=4/ @@ -704,6 +708,12 @@ function isJSON(){str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[ 'function isHtmlNamespace(node){var ns;return typeof node.namespaceURI==UNDEF||((ns=node.namespaceURI)===null||ns=="http://www.w3.org/1999/xhtml")}', ); + // https://github.com/matthiasmullie/minify/issues/115 + $tests[] = array( + 'if(typeof i[s].token=="string")/keyword|support|storage/.test(i[s].token)&&n.push(i[s].regex);else if(typeof i[s].token=="object")for(var u=0,a=i[s].token.length;u