From 44b7acfe666a8dd123519c51137b5f3ab80ddee3 Mon Sep 17 00:00:00 2001 From: Max Ledoux <12563879+maxledoux@users.noreply.github.com> Date: Thu, 22 Sep 2022 15:56:25 -0400 Subject: [PATCH 1/4] search for @charset at any position in $buf --- 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 36bc363..c70b4b7 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -176,7 +176,7 @@ function concat_get_path( $uri ) { ); // The @charset rules must be on top of the output - if ( 0 === strpos( $buf, '@charset' ) ) { + if ( false !== strpos( $buf, '@charset' ) ) { preg_replace_callback( '/(?P@charset\s+[\'"][^\'"]+[\'"];)/i', function ( $match ) { From 86331aae3b90ba6977746c1cd151fcca8062157e Mon Sep 17 00:00:00 2001 From: Max Ledoux <12563879+maxledoux@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:00:21 -0400 Subject: [PATCH 2/4] strip $match[0] from $buf before adding $match[0] to beginning of $pre_output Otherwise we end up with multiple @charset declarations --- ngx-http-concat.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index c70b4b7..80136a0 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -180,11 +180,14 @@ function concat_get_path( $uri ) { preg_replace_callback( '/(?P@charset\s+[\'"][^\'"]+[\'"];)/i', function ( $match ) { - global $pre_output; + global $pre_output, $buf; if ( 0 === strpos( $pre_output, '@charset' ) ) return ''; + //strip $match[0] from $buf before adding it to beginning of $pre_output + $buf = str_replace($match[0], "", $buf); + $pre_output = $match[0] . "\n" . $pre_output; return ''; From 783f2f78ba1475e798a4247adeca2e7f5149aa68 Mon Sep 17 00:00:00 2001 From: Max Ledoux <12563879+maxledoux@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:02:27 -0400 Subject: [PATCH 3/4] rem white space --- ngx-http-concat.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 80136a0..0387ec6 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -180,14 +180,14 @@ function concat_get_path( $uri ) { preg_replace_callback( '/(?P@charset\s+[\'"][^\'"]+[\'"];)/i', function ( $match ) { - global $pre_output, $buf; + global $pre_output, $buf; if ( 0 === strpos( $pre_output, '@charset' ) ) return ''; - //strip $match[0] from $buf before adding it to beginning of $pre_output + //strip $match[0] from $buf before adding $match[0] to beginning of $pre_output $buf = str_replace($match[0], "", $buf); - + $pre_output = $match[0] . "\n" . $pre_output; return ''; From 07621972c9c62de0f03d0342a2189f005df2856e Mon Sep 17 00:00:00 2001 From: Max Ledoux <12563879+maxledoux@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:24:20 -0500 Subject: [PATCH 4/4] apply @sathyapulse notes. --- ngx-http-concat.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 0387ec6..5a5c157 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -177,16 +177,13 @@ function concat_get_path( $uri ) { // The @charset rules must be on top of the output if ( false !== strpos( $buf, '@charset' ) ) { - preg_replace_callback( + $buf = preg_replace_callback( '/(?P@charset\s+[\'"][^\'"]+[\'"];)/i', function ( $match ) { - global $pre_output, $buf; + global $pre_output; if ( 0 === strpos( $pre_output, '@charset' ) ) return ''; - - //strip $match[0] from $buf before adding $match[0] to beginning of $pre_output - $buf = str_replace($match[0], "", $buf); $pre_output = $match[0] . "\n" . $pre_output;