Skip to content

Commit e6a66e0

Browse files
committed
Handle # comment characters inside quotes
#75
1 parent ffecd0e commit e6a66e0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

virtualmin-nginx-lib.pl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ sub flush_config_cache
5454
undef($get_config_cache);
5555
}
5656

57+
# remove_hash_comment(line)
58+
# Returns the line with comments removed
59+
sub remove_hash_comment
60+
{
61+
my ($l) = @_;
62+
if ($l =~ /".*#.*"/) {
63+
# Comment inside quotes, so only remove any comment outside quotes
64+
$l =~ s/#[^"]*$//;
65+
}
66+
else {
67+
# Remove all comments
68+
$l =~ s/#.*$//;
69+
}
70+
return $l;
71+
}
72+
5773
# read_config_file(file, [preserve-includes])
5874
# Returns an array ref of nginx config objects
5975
sub read_config_file
@@ -72,15 +88,15 @@ sub read_config_file
7288
close($fh);
7389
while(@lines) {
7490
my $l = shift(@lines);
75-
$l =~ s/#.*$//;
91+
$l = &remove_hash_comment($l);
7692
my $slnum = $lnum;
7793

7894
# If line doesn't end with { } or ; , it must be continued on the
7995
# next line
8096
while($l =~ /\S/ && $l !~ /[\{\}\;]\s*$/ && @lines) {
8197
my $nl = shift(@lines);
8298
if ($nl =~ /\S/) {
83-
$nl =~ s/#.*$//;
99+
$nl = &remove_hash_comment($nl);
84100
$l .= " ".$nl;
85101
}
86102
$lnum++;

0 commit comments

Comments
 (0)