mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 20:21:01 +01:00
2.03 - fixed bug in the _parse() routine (better: design flaw).
after the last patch for allowing whitespaces in option names, it had a problem with here-docs which contained equal signs. option/value splitting resulted in weird output. - as a side effect of the bug fix below it is now possible to use equal signs inside quoted values, which will then be ignored, thus not used for splitting the line into an option/value assignment. - added a new test, which tests for all possible notations of option/value lines. git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@29 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
14
Changelog
14
Changelog
@@ -1,3 +1,17 @@
|
|||||||
|
2.03 - fixed bug in the _parse() routine (better: design flaw).
|
||||||
|
after the last patch for allowing whitespaces in
|
||||||
|
option names, it had a problem with here-docs which
|
||||||
|
contained equal signs. option/value splitting resulted
|
||||||
|
in weird output.
|
||||||
|
|
||||||
|
- as a side effect of the bug fix below it is now
|
||||||
|
possible to use equal signs inside quoted values, which
|
||||||
|
will then be ignored, thus not used for splitting
|
||||||
|
the line into an option/value assignment.
|
||||||
|
|
||||||
|
- added a new test, which tests for all possible notations
|
||||||
|
of option/value lines.
|
||||||
|
|
||||||
2.02 - added patch by Jens Heunemann, which allows to use
|
2.02 - added patch by Jens Heunemann, which allows to use
|
||||||
whitespaces in option names.
|
whitespaces in option names.
|
||||||
|
|
||||||
|
|||||||
30
General.pm
30
General.pm
@@ -17,7 +17,7 @@ use strict;
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
|
|
||||||
$Config::General::VERSION = "2.02";
|
$Config::General::VERSION = "2.03";
|
||||||
|
|
||||||
use vars qw(@ISA @EXPORT);
|
use vars qw(@ISA @EXPORT);
|
||||||
@ISA = qw(Exporter);
|
@ISA = qw(Exporter);
|
||||||
@@ -344,24 +344,30 @@ sub _parse {
|
|||||||
my($this, $config, $content) = @_;
|
my($this, $config, $content) = @_;
|
||||||
my(@newcontent, $block, $blockname, $grab, $chunk,$block_level);
|
my(@newcontent, $block, $blockname, $grab, $chunk,$block_level);
|
||||||
local $_;
|
local $_;
|
||||||
|
my $indichar = chr(182); # <20>, inserted by _open, our here-doc indicator
|
||||||
|
|
||||||
foreach (@{$content}) { # loop over content stack
|
foreach (@{$content}) { # loop over content stack
|
||||||
chomp;
|
chomp;
|
||||||
$chunk++;
|
$chunk++;
|
||||||
$_ =~ s/^\s*//; # strip spaces @ end and begin
|
$_ =~ s/^\s*//; # strip spaces @ end and begin
|
||||||
$_ =~ s/\s*$//;
|
$_ =~ s/\s*$//;
|
||||||
|
|
||||||
# my ($option,$value) = split /\s*=\s*|\s+/, $_, 2; # option/value assignment, = is optional
|
#
|
||||||
|
# build option value assignment, split current input
|
||||||
|
# using whitespace, equal sign or optionally here-doc
|
||||||
|
# separator (ascii 182).
|
||||||
|
my ($option,$value);
|
||||||
|
if (/$indichar/) {
|
||||||
|
($option,$value) = split /\s*$indichar\s*/, $_, 2; # separated by heredoc-finding in _open()
|
||||||
|
}
|
||||||
|
elsif (/^[^\"]+?=/) {
|
||||||
|
($option,$value) = split /\s*=\s*/, $_, 2; # using equal if not inside quotes
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
($option,$value) = split /\s+/, $_, 2; # option/value assignment, = is optional
|
||||||
|
}
|
||||||
|
|
||||||
my ($option,$value);
|
|
||||||
if (/=/) {
|
|
||||||
($option,$value) = split /\s*=\s*/, $_, 2; # option/value assignment, = is optional
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
($option,$value) = split /\s+/, $_, 2; # option/value assignment, = is optional
|
|
||||||
}
|
|
||||||
|
|
||||||
my $indichar = chr(182); # <20>, inserted by _open, our here-doc indicator
|
|
||||||
$value =~ s/^$indichar// if($value); # a here-doc begin, remove indicator
|
|
||||||
if ($value && $value =~ /^"/ && $value =~ /"$/) {
|
if ($value && $value =~ /^"/ && $value =~ /"$/) {
|
||||||
$value =~ s/^"//; # remove leading and trailing "
|
$value =~ s/^"//; # remove leading and trailing "
|
||||||
$value =~ s/"$//;
|
$value =~ s/"$//;
|
||||||
@@ -1575,7 +1581,7 @@ Thomas Linden <tom@daemon.de>
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
2.02
|
2.03
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
16
t/cfg.19
Normal file
16
t/cfg.19
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#
|
||||||
|
# these options must all in
|
||||||
|
# msg[\d] keys.
|
||||||
|
#
|
||||||
|
msg1 = "Das ist ein Test"
|
||||||
|
msg2 = "Das = ein Test"
|
||||||
|
msg3 "Das ist ein Test"
|
||||||
|
msg4 "Das = ein Test"
|
||||||
|
|
||||||
|
msg6 = <<EOF
|
||||||
|
Das = ein Test
|
||||||
|
EOF
|
||||||
|
|
||||||
|
msg7 <<EOF
|
||||||
|
Das = ein Test
|
||||||
|
msg7
|
||||||
9
t/cfg.4
9
t/cfg.4
@@ -1,7 +1,14 @@
|
|||||||
|
/*
|
||||||
# Here-document test
|
# Here-document test
|
||||||
message <<EOF
|
message = <<EOF
|
||||||
yes. we are not here. you
|
yes. we are not here. you
|
||||||
can reach us somewhere in
|
can reach us somewhere in
|
||||||
outerspace.
|
outerspace.
|
||||||
# and this line will remain inside the here-doc!
|
# and this line will remain inside the here-doc!
|
||||||
EOF
|
EOF
|
||||||
|
*/
|
||||||
|
|
||||||
|
header = <<EOF
|
||||||
|
<table border="0">
|
||||||
|
</table>
|
||||||
|
EOF
|
||||||
20
t/run.t
20
t/run.t
@@ -6,7 +6,7 @@
|
|||||||
#
|
#
|
||||||
# Under normal circumstances every test should succeed.
|
# Under normal circumstances every test should succeed.
|
||||||
|
|
||||||
BEGIN { $| = 1; print "1..18\n";}
|
BEGIN { $| = 1; print "1..19\n";}
|
||||||
use lib "blib/lib";
|
use lib "blib/lib";
|
||||||
use Config::General;
|
use Config::General;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
@@ -170,7 +170,23 @@ else {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# testing various otion/value assignemnt notations
|
||||||
|
my $conf19 = new Config::General(-file => "t/cfg.19");
|
||||||
|
my %h19 = $conf19->getall();
|
||||||
|
my $works = 1;
|
||||||
|
foreach my $key (keys %h19) {
|
||||||
|
if ($key =~ /\s/) {
|
||||||
|
$works = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($works) {
|
||||||
|
print "ok\n";
|
||||||
|
print STDERR " .. ok # Testing various otion/value assignemnt notations\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "19 not ok\n";
|
||||||
|
print STDERR "19 not ok\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user