From f5ac2b6b7529b989e545b086ada868df32d06b05 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sat, 10 Oct 2009 16:22:10 +0000 Subject: [PATCH] 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 --- Changelog | 14 ++++++++++++++ General.pm | 30 ++++++++++++++++++------------ README | 2 +- t/cfg.19 | 16 ++++++++++++++++ t/cfg.4 | 9 ++++++++- t/run.t | 20 ++++++++++++++++++-- 6 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 t/cfg.19 diff --git a/Changelog b/Changelog index 2a80266..94f24ea 100644 --- a/Changelog +++ b/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 whitespaces in option names. diff --git a/General.pm b/General.pm index f49602f..42498ff 100644 --- a/General.pm +++ b/General.pm @@ -17,7 +17,7 @@ use strict; use Carp; use Exporter; -$Config::General::VERSION = "2.02"; +$Config::General::VERSION = "2.03"; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @@ -344,24 +344,30 @@ sub _parse { my($this, $config, $content) = @_; my(@newcontent, $block, $blockname, $grab, $chunk,$block_level); local $_; + my $indichar = chr(182); # ¶, inserted by _open, our here-doc indicator + foreach (@{$content}) { # loop over content stack chomp; $chunk++; $_ =~ s/^\s*//; # strip spaces @ end and begin $_ =~ 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); # ¶, inserted by _open, our here-doc indicator - $value =~ s/^$indichar// if($value); # a here-doc begin, remove indicator if ($value && $value =~ /^"/ && $value =~ /"$/) { $value =~ s/^"//; # remove leading and trailing " $value =~ s/"$//; @@ -1575,7 +1581,7 @@ Thomas Linden =head1 VERSION -2.02 +2.03 =cut diff --git a/README b/README index 89702ea..df159df 100644 --- a/README +++ b/README @@ -98,4 +98,4 @@ AUTHOR VERSION - 2.02 + 2.03 diff --git a/t/cfg.19 b/t/cfg.19 new file mode 100644 index 0000000..5b0d899 --- /dev/null +++ b/t/cfg.19 @@ -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 \ No newline at end of file diff --git a/t/run.t b/t/run.t index 2323c2a..baf2a71 100644 --- a/t/run.t +++ b/t/run.t @@ -6,7 +6,7 @@ # # Under normal circumstances every test should succeed. -BEGIN { $| = 1; print "1..18\n";} +BEGIN { $| = 1; print "1..19\n";} use lib "blib/lib"; use Config::General; 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"; +}