Subject: | Line continuations ('\') |
Hi,
Apache::ConfigFile 1.18 doesn't handle line continuations (denoted by a backslash at the end of the line). I'm attaching a patch by Gunnar Wolf that fixes this. It is included in the Debian version of Apache::ConfigFile.
(For reference, this was originally reported as Debian bug #309721, http://bugs.debian.org/309721 .)
--
Niko Tyni
ntyni@iki.fi
--- libapache-configfile-perl-1.18.orig/ConfigFile.pm
+++ libapache-configfile-perl-1.18/ConfigFile.pm
@@ -199,15 +199,28 @@
my $cmd_context = $conf;
my @parselevel = ();
my $line = 0;
+ my $cont_confline = '';
- foreach (@conf) {
+ foreach my $confline (@conf) {
$line++;
+ # Handle line continuation when a trailing \ is found
+ if ($cont_confline) {
+ # This line is a continuation
+ $confline = "$cont_confline $confline";
+ $cont_confline = '';
+ }
+ if ($confline =~ /^(.+)\\\s*$/) {
+ # This line continues in the next one
+ $cont_confline = $1;
+ next;
+ }
+
# Strip newlines/comments
- s/\s*#.*//;
+ $confline =~ s/\s*#.*//;
# If nothing's left, continue
- next unless $_;
+ next unless $confline;
# This substitutes in re-used variable on the right side of the file
# We have to handle the ignore_case flag hence the expression
@@ -215,17 +228,17 @@
# are visible for re-substitution
if ($self->{expand_vars}) {
local($^W) = 0 ;
- s#\$\{?(\w+)\}?#my $k = $self->_fixcase($1);$conf->{$k}#eg;
+ $confline =~ s#\$\{?(\w+)\}?#my $k = $self->_fixcase($1);$conf->{$k}#eg;
}
# This may be a <stuff> junk </stuff>, in which case we need
# to nest our data struct!
- if (m#^\s*</(\S+)\s*>\s*$#) {
+ if ($confline =~ m#^\s*</(\S+)\s*>\s*$#) {
# match </close> - walk up
$cmd_context = pop @parselevel;
$self->_error("$file line $line: Mismatched closing tag '$1'") unless $cmd_context;
next;
- } elsif (m#^\s*<(\S+)\s*(["']*)(.*)\2>\s*$#) {
+ } elsif ($confline =~ m#^\s*<(\S+)\s*(["']*)(.*)\2>\s*$#) {
# create new sublevel in parsing
my $k = $self->_fixcase($1);
push @parselevel, $cmd_context;
@@ -248,8 +261,8 @@
# Split up the key and the value. The @val regexp code dynamically
# differentiates between "space strings" and array, values.
- my($key, $r) = m!^\s*\s*(\w+)\s*(?=\s+)(.*)!; # split up key
- my(@val) = $r =~ m!\s+(?:"([^"]*[^\\])"|([^\s,]+))\n?!g; # split up val
+ my($key, $r) = $confline =~ m!^\s*\s*(\w+)\s*(?=\s+)(.*)!; # split up key
+ my(@val) = $r =~ m!\s+(?:\"([^\"]*[^\\])\"|([^\s,]+))\n?!g; # split up val
@val = grep { defined } @val; # lose undef values
# Check for "on/off" or "true/false" or "yes/no"