From 5567928fdc7a19411119db87a79cf02b765f48c9 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Fri, 21 Aug 2020 11:42:59 +0200 Subject: [PATCH 1/4] Wrap each javascript into their own function to prevent strict mode from leaking to other scripts --- ngx-http-concat.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index a2a73bd..9793c45 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -216,10 +216,13 @@ function ( $match ) use ( $dirpath ) { $buf = $css_minify->run( $buf ); } - if ( 'application/x-javascript' == $mime_type ) + if ( 'application/x-javascript' == $mime_type ) { + $output .= "(function(window, document, undefined) {\n"; $output .= "$buf;\n"; - else + $output .= "\n})(window, document);\n"; + } else { $output .= "$buf"; + } } header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $last_modified ) . ' GMT' ); From 724549c98a642a5ac898c68aa6d37a56185b5aea Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Fri, 21 Aug 2020 11:55:52 +0200 Subject: [PATCH 2/4] Group suffixes together --- ngx-http-concat.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 9793c45..c4f9a2a 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -218,8 +218,8 @@ function ( $match ) use ( $dirpath ) { if ( 'application/x-javascript' == $mime_type ) { $output .= "(function(window, document, undefined) {\n"; - $output .= "$buf;\n"; - $output .= "\n})(window, document);\n"; + $output .= $buf; + $output .= ";\n})(window, document);\n"; } else { $output .= "$buf"; } From 7a5334017a5aa5f8531832e0cff01db35d35f688 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Fri, 21 Aug 2020 12:08:16 +0200 Subject: [PATCH 3/4] semicolon is not needed anymore --- ngx-http-concat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index c4f9a2a..265e2ab 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -219,7 +219,7 @@ function ( $match ) use ( $dirpath ) { if ( 'application/x-javascript' == $mime_type ) { $output .= "(function(window, document, undefined) {\n"; $output .= $buf; - $output .= ";\n})(window, document);\n"; + $output .= "\n})(window, document);\n"; } else { $output .= "$buf"; } From d1fd5e4bd6c4267cb09ec38fae2e6d4b800471dd Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Fri, 21 Aug 2020 13:10:18 +0200 Subject: [PATCH 4/4] Add special case for JS and make sure this copies the upper function context --- ngx-http-concat.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 265e2ab..c513820 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -217,9 +217,11 @@ function ( $match ) use ( $dirpath ) { } if ( 'application/x-javascript' == $mime_type ) { + $output .= "$buf;\n"; + } else if ( $concat_types['js'] == $mime_type ) { $output .= "(function(window, document, undefined) {\n"; $output .= $buf; - $output .= "\n})(window, document);\n"; + $output .= "\n}).call(this, window, document);\n"; } else { $output .= "$buf"; }