From 78e0f318992fa2156b9860a5873e335e9f34115b Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Mon, 7 Sep 2026 03:55:19 +0200 Subject: [PATCH] Fix to quote directive values containing # MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⓘ Values with a # were written unquoted, so on the next read the module took the # as the start of a comment and lost the rest of the line. For example, a redirect saved as return 301 https://example.com/docs#install; then showed as no redirect on the page, and re-saving it added a duplicate rewrite_log directive that Nginx rejected. So, before the fix, saving a redirect to https://example.com/docs#install wrote: return 301 https://example.com/docs#install; rewrite_log off; On the next read the module dropped everything after the #, so it saw one merged line: return 301 https://example.com/docs rewrite_log off; The redirect disappeared from the page, and saving again appended a second rewrite_log off;, which Nginx rejects as a duplicate. After the fix the same save writes: return 301 "https://example.com/docs#install"; rewrite_log off; Nginx treats the quoted and unquoted forms identically, and the module reads it back correctly. --- nginx/nginx-lib.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nginx/nginx-lib.pl b/nginx/nginx-lib.pl index 8d0107b29..77d4b27e6 100644 --- a/nginx/nginx-lib.pl +++ b/nginx/nginx-lib.pl @@ -731,13 +731,15 @@ sub join_words { my @rv; foreach my $w (@_) { + # Quote words with spaces, separators, variables or a # comment marker + my $quote = $w =~ /\s|;|\$/ && $w !~ /^\$/ || $w =~ /#/; if ($w eq "") { push(@rv, '""'); } - elsif ($w =~ /\s|;|\$/ && $w !~ /"/ && $w !~ /^\$/) { + elsif ($quote && $w !~ /"/) { push(@rv, "\"$w\""); } - elsif ($w =~ /\s|;|\$/ && $w !~ /^\$/) { + elsif ($quote) { push(@rv, "'$w'"); } else {