From f091f3b9e6bece4b8ef9da1d08a4a6220ad8d3ac Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Wed, 25 Oct 2017 08:48:20 +0200 Subject: [PATCH] Regexes can also start in array Fixes #209 --- src/JS.php | 2 +- tests/js/JSTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/JS.php b/src/JS.php index eb72df4..6fbf559 100644 --- a/src/JS.php +++ b/src/JS.php @@ -257,7 +257,7 @@ protected function extractRegex() // of the RegExp methods (a `\` followed by a variable or value is // likely part of a division, not a regex) $keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof'); - $before = '(?P[=:,;\}\(\{&\|!]|^|'.implode('|', $keywords).')'; + $before = '(?P[=:,;\}\(\{\[&\|!]|^|'.implode('|', $keywords).')'; $propertiesAndMethods = array( // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Properties_2 'constructor', diff --git a/tests/js/JSTest.php b/tests/js/JSTest.php index 97118d1..cc4f1b4 100644 --- a/tests/js/JSTest.php +++ b/tests/js/JSTest.php @@ -1171,6 +1171,12 @@ function someOtherFunction() { '\'//\'.match(/\/|\'/)', ); + // https://github.com/matthiasmullie/minify/issues/209 + $tests[] = array( + 'var my_regexes = [/[a-z]{3}\//g, \'a string\', 1];', + 'var my_regexes=[/[a-z]{3}\//g,\'a string\',1]', + ); + // known minified files to help doublecheck changes in places not yet // anticipated in these tests $files = glob(__DIR__.'/sample/minified/*.js');