File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,22 @@ sub flush_config_cache
54
54
undef ($get_config_cache );
55
55
}
56
56
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
+
57
73
# read_config_file(file, [preserve-includes])
58
74
# Returns an array ref of nginx config objects
59
75
sub read_config_file
@@ -72,15 +88,15 @@ sub read_config_file
72
88
close ($fh );
73
89
while (@lines ) {
74
90
my $l = shift (@lines );
75
- $l =~ s / #.*$ // ;
91
+ $l = &remove_hash_comment( $l ) ;
76
92
my $slnum = $lnum ;
77
93
78
94
# If line doesn't end with { } or ; , it must be continued on the
79
95
# next line
80
96
while ($l =~ / \S / && $l !~ / [\{\}\; ]\s *$ / && @lines ) {
81
97
my $nl = shift (@lines );
82
98
if ($nl =~ / \S / ) {
83
- $nl =~ s / #.*$ // ;
99
+ $nl = &remove_hash_comment( $nl ) ;
84
100
$l .= " " .$nl ;
85
101
}
86
102
$lnum ++;
You can’t perform that action at this time.
0 commit comments