froxlor / Froxlor

The server administration software for your needs - The official Froxlor development Git repository
http://www.froxlor.org
GNU General Public License v2.0
1.63k stars 453 forks source link

Curly braces in rewrite result in broken formatting in nginx config #1171

Closed lukasbableck closed 1 year ago

lukasbableck commented 1 year ago

Describe the bug If a rewrite in the vHost settings for a domain contains curly braces Froxlor seems to add whitespace around those braces, obviously breaking the rewrite.

This

Bildschirmfoto 2023-08-22 um 08 20 45

results in

image

System information

To Reproduce Steps to reproduce the behavior:

  1. Go to any domain
  2. Add for example 'rewrite "^/\d{4}/\d{2}/\d{2}(/.*)$" $1 permanent;' to it's vhost settings
  3. Check generated vhost config and see incorrectly formatted rewrite

Expected behavior No whitespaces before and after curly braces if they are part of a string

d00p commented 1 year ago

This requires some deep work in the nginx-custom-config merge process. The cause it not the replacers but the curly brackets itself being opening and closing blocks. We'll see what we can do

d00p commented 1 year ago

Could you test the following patch and check whether it works as intended?

diff --git a/lib/Froxlor/Cron/Http/Nginx.php b/lib/Froxlor/Cron/Http/Nginx.php
index 76ad0471..c0cf4749 100644
--- a/lib/Froxlor/Cron/Http/Nginx.php
+++ b/lib/Froxlor/Cron/Http/Nginx.php
@@ -883,13 +883,7 @@ class Nginx extends HttpConfigBase
                // remove comments
                $vhost = implode("\n", preg_replace('/^(\s+)?#(.*)$/', '', explode("\n", $vhost)));
                // Break blocks into lines
-               $vhost = str_replace([
-                       "{",
-                       "}"
-               ], [
-                       " {\n",
-                       "\n}"
-               ], $vhost);
+               $vhost = preg_replace("/^(\s+)location(.+)\{(.+)\}$/misU", "location $2 {\n $3 \n}", $vhost);
                // Break into array items
                $vhost = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost))));
                // Remove empty lines
lukasbableck commented 1 year ago

Yes, seems to work fine.

image
d00p commented 1 year ago

fixed in 9d0e463906c4f2df3ac39aafdca2737260d2e433