Skip to content

Commit 3f9cebc

Browse files
Require that a regex has some content
Otherwise, the `//` that start a comment could be misread as regexes. Fixes #196
1 parent 0913101 commit 3f9cebc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/JS.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function extractRegex()
242242
(isset($match['after']) ? $match['after'] : '');
243243
};
244244

245-
$pattern = '(?P<regex>\/.*?(?<!\\\\)(\\\\\\\\)*\/[gimy]*)(?![0-9a-zA-Z\/])';
245+
$pattern = '(?P<regex>\/(.|\\\\)+?((?<!\\\\)\\\\\\\\)*\/[gimy]*)(?![0-9a-zA-Z\/])';
246246

247247
// a regular expression can only be followed by a few operators or some
248248
// of the RegExp methods (a `\` followed by a variable or value is

tests/js/JSTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,17 @@ function someOtherFunction() {
11151115
'if(!0||/^(https?:)?\/\//.test(\'xxx\'))alert(1)',
11161116
);
11171117

1118+
// https://github.com/matthiasmullie/minify/issues/196
1119+
$tests[] = array(
1120+
'if ( true ) {
1121+
console.log(true);
1122+
// ...comment number 2 (something with dots?)
1123+
} else {
1124+
console.log(false);
1125+
}',
1126+
'if(!0){console.log(!0)}else{console.log(!1)}',
1127+
);
1128+
11181129
// known minified files to help doublecheck changes in places not yet
11191130
// anticipated in these tests
11201131
$files = glob(__DIR__.'/sample/minified/*.js');

0 commit comments

Comments
 (0)