From d475a1f366784e7a660fcce36d5ac69cc36705f5 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Tue, 7 Mar 2023 19:57:42 +0530 Subject: [PATCH 1/3] To identify coorect end of the regex --- src/JShrink/Minifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JShrink/Minifier.php b/src/JShrink/Minifier.php index 3f07ad8..9e6c781 100644 --- a/src/JShrink/Minifier.php +++ b/src/JShrink/Minifier.php @@ -626,7 +626,7 @@ protected function saveRegex() $this->echo($this->b); while (($this->a = $this->getChar()) !== false) { - if ($this->a === '/') { + if ($this->a === '/' && (preg_match('/g|\n|i|\.|,|\s/', $this->peek()) === 1)) { break; } From 962daa7954dfaeb06de7db1578e49df83009fe87 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Tue, 7 Mar 2023 20:48:07 +0530 Subject: [PATCH 2/3] To identify coorect end of the regex --- tests/Resources/jshrink/input/regex_end_string.js | 3 +++ tests/Resources/jshrink/output/regex_end_string.js | 1 + 2 files changed, 4 insertions(+) create mode 100644 tests/Resources/jshrink/input/regex_end_string.js create mode 100644 tests/Resources/jshrink/output/regex_end_string.js diff --git a/tests/Resources/jshrink/input/regex_end_string.js b/tests/Resources/jshrink/input/regex_end_string.js new file mode 100644 index 0000000..79164ff --- /dev/null +++ b/tests/Resources/jshrink/input/regex_end_string.js @@ -0,0 +1,3 @@ +escapeCssMeta: function( string ) { + return (string || '').replace( /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1" ); +}, \ No newline at end of file diff --git a/tests/Resources/jshrink/output/regex_end_string.js b/tests/Resources/jshrink/output/regex_end_string.js new file mode 100644 index 0000000..1311d14 --- /dev/null +++ b/tests/Resources/jshrink/output/regex_end_string.js @@ -0,0 +1 @@ +escapeCssMeta:function(string){return(string||'').replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g,"\\$1");}, \ No newline at end of file From 70b18f1808946473908ed29384ef0c3c5de0beb4 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 16 Mar 2023 18:30:12 +0530 Subject: [PATCH 3/3] To identify coorect end of the regex --- src/JShrink/Minifier.php | 2 +- tests/Resources/jshrink/output/regex_close.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/JShrink/Minifier.php b/src/JShrink/Minifier.php index 9e6c781..365c474 100644 --- a/src/JShrink/Minifier.php +++ b/src/JShrink/Minifier.php @@ -626,7 +626,7 @@ protected function saveRegex() $this->echo($this->b); while (($this->a = $this->getChar()) !== false) { - if ($this->a === '/' && (preg_match('/g|\n|i|\.|,|\s/', $this->peek()) === 1)) { + if ($this->a === '/' && (preg_match('/g|\n|i|\)|\.|,|\s/', $this->peek()) === 1)) { break; } diff --git a/tests/Resources/jshrink/output/regex_close.js b/tests/Resources/jshrink/output/regex_close.js index 4f80faf..fb0880d 100644 --- a/tests/Resources/jshrink/output/regex_close.js +++ b/tests/Resources/jshrink/output/regex_close.js @@ -1,4 +1 @@ -function test(string){return(string||'').replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, - '\\$1' - ) -} +function test(string){return(string||'').replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g,'\\$1')} \ No newline at end of file