mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-17 12:41:07 +01:00
2.13 - fixed bug reported by Steffen Schwigon <schwigon@webit.de>.
the parser was still active inside a here-doc, which cause weird results if the here-doc contained multiple <<XXX strings. this bug has been fixed by re-organizing the _read() method. now the parser is only active outside of here-docs. - here-doc parsing bug fixed, which ignored the -SplitPolicy settings completely, now it is aware of the split policy git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@39 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
12
Changelog
12
Changelog
@@ -1,3 +1,15 @@
|
|||||||
|
2.13 - fixed bug reported by Steffen Schwigon <schwigon@webit.de>.
|
||||||
|
the parser was still active inside a here-doc, which
|
||||||
|
cause weird results if the here-doc contained
|
||||||
|
multiple <<XXX strings.
|
||||||
|
this bug has been fixed by re-organizing the _read()
|
||||||
|
method. now the parser is only active outside of
|
||||||
|
here-docs.
|
||||||
|
|
||||||
|
- here-doc parsing bug fixed, which ignored the
|
||||||
|
-SplitPolicy settings completely, now it is aware
|
||||||
|
of the split policy
|
||||||
|
|
||||||
2.12 - fixed cpan bugid #1768, stuff inside a hash given
|
2.12 - fixed cpan bugid #1768, stuff inside a hash given
|
||||||
by the -DefaultConfig parameter was ignored by
|
by the -DefaultConfig parameter was ignored by
|
||||||
the new interpolation code, this has been fixed.
|
the new interpolation code, this has been fixed.
|
||||||
|
|||||||
171
General.pm
171
General.pm
@@ -17,7 +17,7 @@ use strict;
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
|
|
||||||
$Config::General::VERSION = "2.12";
|
$Config::General::VERSION = "2.13";
|
||||||
|
|
||||||
use vars qw(@ISA @EXPORT);
|
use vars qw(@ISA @EXPORT);
|
||||||
@ISA = qw(Exporter);
|
@ISA = qw(Exporter);
|
||||||
@@ -313,12 +313,15 @@ sub _read {
|
|||||||
chomp;
|
chomp;
|
||||||
|
|
||||||
if ($this->{CComments}) {
|
if ($this->{CComments}) {
|
||||||
|
# look for C-Style comments, if activated
|
||||||
if (/(\s*\/\*.*\*\/\s*)/) {
|
if (/(\s*\/\*.*\*\/\s*)/) {
|
||||||
# single c-comment on one line
|
# single c-comment on one line
|
||||||
s/\s*\/\*.*\*\/\s*//;
|
s/\s*\/\*.*\*\/\s*//;
|
||||||
}
|
}
|
||||||
elsif (/^\s*\/\*/) { # the beginning of a C-comment ("/*"), from now on ignore everything.
|
elsif (/^\s*\/\*/) {
|
||||||
if (/\*\/\s*$/) { # C-comment end is already there, so just ignore this line!
|
# the beginning of a C-comment ("/*"), from now on ignore everything.
|
||||||
|
if (/\*\/\s*$/) {
|
||||||
|
# C-comment end is already there, so just ignore this line!
|
||||||
$c_comment = 0;
|
$c_comment = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -329,74 +332,118 @@ sub _read {
|
|||||||
if (!$c_comment) {
|
if (!$c_comment) {
|
||||||
warn "invalid syntax: found end of C-comment without previous start!\n";
|
warn "invalid syntax: found end of C-comment without previous start!\n";
|
||||||
}
|
}
|
||||||
$c_comment = 0; # the current C-comment ends here, go on
|
$c_comment = 0; # the current C-comment ends here, go on
|
||||||
s/^.*\*\///; # if there is still stuff, it will be read
|
s/^.*\*\///; # if there is still stuff, it will be read
|
||||||
}
|
}
|
||||||
next if($c_comment); # ignore EVERYTHING from now on
|
next if($c_comment); # ignore EVERYTHING from now on, IF it IS a C-Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$hierend) { # patch by "Manuel Valente" <manuel@ripe.net>:
|
|
||||||
s/(?<!\\)#.+$//; # Remove comments
|
|
||||||
next if /^\s*#/; # Remove lines beginning with "#"
|
|
||||||
next if /^\s*$/; # Skip empty lines
|
|
||||||
s/\\#/#/g; # remove the \ char in front of masked "#"
|
|
||||||
}
|
|
||||||
if (/^\s*(\S+?)(\s*=\s*|\s+)<<(.+?)$/) { # we are @ the beginning of a here-doc
|
|
||||||
$hier = $1; # $hier is the actual here-doc
|
|
||||||
$hierend = $3; # the here-doc end string, i.e. "EOF"
|
|
||||||
}
|
|
||||||
elsif (defined $hierend && /^(\s*)\Q$hierend\E\s*$/) { # the current here-doc ends here (allow spaces)
|
|
||||||
my $indent = $1; # preserve indentation
|
|
||||||
$hier .= " " . chr(182); # append a "<22>" to the here-doc-name, so _parse will also preserver indentation
|
|
||||||
if ($indent) {
|
|
||||||
foreach (@hierdoc) {
|
|
||||||
s/^$indent//; # i.e. the end was: " EOF" then we remove " " from every here-doc line
|
|
||||||
$hier .= $_ . "\n"; # and store it in $hier
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$hier .= join "\n", @hierdoc; # there was no indentation of the end-string, so join it 1:1
|
|
||||||
}
|
|
||||||
push @{$this->{content}}, $hier; # push it onto the content stack
|
|
||||||
@hierdoc = ();
|
|
||||||
undef $hier;
|
|
||||||
undef $hierend;
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif (/\\$/) { # a multiline option, indicated by a trailing backslash
|
if ($hier) {
|
||||||
chop;
|
# inside here-doc, only look for $hierend marker
|
||||||
s/^\s*//;
|
if (/^(\s*)\Q$hierend\E\s*$/) {
|
||||||
$longline .= $_; # store in $longline
|
my $indent = $1; # preserve indentation
|
||||||
}
|
$hier .= " " . chr(182); # append a "<22>" to the here-doc-name, so
|
||||||
else { # any "normal" config lines
|
# _parse will also preserver indentation
|
||||||
if ($longline) { # previous stuff was a longline and this is the last line of the longline
|
if ($indent) {
|
||||||
s/^\s*//;
|
foreach (@hierdoc) {
|
||||||
$longline .= $_;
|
s/^$indent//; # i.e. the end was: " EOF" then we remove " " from every here-doc line
|
||||||
push @{$this->{content}}, $longline; # push it onto the content stack
|
$hier .= $_ . "\n"; # and store it in $hier
|
||||||
undef $longline;
|
|
||||||
}
|
|
||||||
elsif ($hier) { # we are inside a here-doc
|
|
||||||
push @hierdoc, $_; # push onto here-dco stack
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# look for include statement(s)
|
|
||||||
my $incl_file;
|
|
||||||
if (/^\s*<<include\s+(.+?)>>\s*$/i || (/^\s*include\s+(.+?)\s*$/i && $this->{UseApacheInclude})) {
|
|
||||||
$incl_file = $1;
|
|
||||||
if ($this->{IncludeRelative} && $this->{configpath} && $incl_file !~ /^\//) {
|
|
||||||
# include the file from within location of $this->{configfile}
|
|
||||||
$this->_open($this->{configpath} . "/" . $incl_file);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# include the file from within pwd, or absolute
|
|
||||||
$this->_open($incl_file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
push @{$this->{content}}, $_;
|
$hier .= join "\n", @hierdoc; # there was no indentation of the end-string, so join it 1:1
|
||||||
}
|
}
|
||||||
|
push @{$this->{content}}, $hier; # push it onto the content stack
|
||||||
|
@hierdoc = ();
|
||||||
|
undef $hier;
|
||||||
|
undef $hierend;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# everything else onto the stack
|
||||||
|
push @hierdoc, $_;
|
||||||
|
}
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
### non-heredoc entries from now on
|
||||||
|
##
|
||||||
|
|
||||||
|
# Remove comments and empty lines
|
||||||
|
s/(?<!\\)#.+$//;
|
||||||
|
next if /^\s*#/;
|
||||||
|
next if /^\s*$/;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# remove the \ char in front of masked "#", if any
|
||||||
|
s/\\#/#/g;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# look for here-doc identifier
|
||||||
|
if ($this->{SplitPolicy} eq 'guess') {
|
||||||
|
if (/^\s*(\S+?)(\s*=\s*|\s+)<<\s*(.+?)\s*$/) {
|
||||||
|
$hier = $1; # the actual here-doc variable name
|
||||||
|
$hierend = $3; # the here-doc identifier, i.e. "EOF"
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
# no guess, use one of the configured strict split policies
|
||||||
|
if (/^\s*(\S+?)($this->{SplitDelimiter})<<\s*(.+?)\s*$/) {
|
||||||
|
$hier = $1; # the actual here-doc variable name
|
||||||
|
$hierend = $3; # the here-doc identifier, i.e. "EOF"
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# look for multiline option, indicated by a trailing backslash
|
||||||
|
if (/\\$/) {
|
||||||
|
chop;
|
||||||
|
s/^\s*//;
|
||||||
|
$longline .= $_;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
### any "normal" config lines from now on
|
||||||
|
###
|
||||||
|
|
||||||
|
if ($longline) {
|
||||||
|
# previous stuff was a longline and this is the last line of the longline
|
||||||
|
s/^\s*//;
|
||||||
|
$longline .= $_;
|
||||||
|
push @{$this->{content}}, $longline; # push it onto the content stack
|
||||||
|
undef $longline;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# look for include statement(s)
|
||||||
|
my $incl_file;
|
||||||
|
if (/^\s*<<include\s+(.+?)>>\s*$/i || (/^\s*include\s+(.+?)\s*$/i && $this->{UseApacheInclude})) {
|
||||||
|
$incl_file = $1;
|
||||||
|
if ($this->{IncludeRelative} && $this->{configpath} && $incl_file !~ /^\//) {
|
||||||
|
# include the file from within location of $this->{configfile}
|
||||||
|
$this->_open($this->{configpath} . "/" . $incl_file);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# include the file from within pwd, or absolute
|
||||||
|
$this->_open($incl_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# standard entry, (option = value)
|
||||||
|
push @{$this->{content}}, $_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1741,7 +1788,7 @@ Thomas Linden <tom@daemon.de>
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
2.12
|
2.13
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user