From 61ed23ca3aa90a2c6d5dd6834d5c972da17f7a29 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 20 May 2015 17:28:38 +0000 Subject: [PATCH] fix rt.cpan.org#104548 git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@102 be1acefe-a474-0410-9a34-9b3221f2030f --- Changelog | 7 +++++++ General.pm | 11 ++++++++--- README | 2 +- t/run.t | 8 +++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 0369555..611494f 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,10 @@ +2.57 - fix rt.cpan.org#104548, dont allow special chars like newline + or < in keys, which leads to faile when saving. + +2.56 - fix rt.cpan.org#95325 + +2.55 - fix rt.cpan.org#95314 + 2.54 - fixed rt.cpan.org#39814. changed the order of pre-processing in _read(): 1) remove comments, 2) check for continuation, 3) remove empty lines. diff --git a/General.pm b/General.pm index f3643b3..a80f23b 100644 --- a/General.pm +++ b/General.pm @@ -5,7 +5,7 @@ # config values from a given file and # return it as hash structure # -# Copyright (c) 2000-2014 Thomas Linden . +# Copyright (c) 2000-2015 Thomas Linden . # All Rights Reserved. Std. disclaimer applies. # Artistic License, same as perl itself. Have fun. # @@ -32,7 +32,7 @@ use Carp::Heavy; use Carp; use Exporter; -$Config::General::VERSION = "2.56"; +$Config::General::VERSION = "2.57"; use vars qw(@ISA @EXPORT_OK); use base qw(Exporter); @@ -1258,6 +1258,11 @@ sub _store { my $config_string = q(); foreach my $entry ( $this->{SaveSorted} ? sort keys %$config : keys %$config ) { + # fix rt#104548 + if ($entry =~ /[<>\n\r]/) { + croak "Config::General: current key contains invalid characters: $entry!\n"; + } + if (ref($config->{$entry}) eq 'ARRAY') { if( $this->{ForceArray} && scalar @{$config->{$entry}} == 1 && ! ref($config->{$entry}->[0]) ) { # a single value array forced to stay as array @@ -2748,7 +2753,7 @@ Thomas Linden =head1 VERSION -2.56 +2.57 =cut diff --git a/README b/README index 7d3eafc..956ba91 100644 --- a/README +++ b/README @@ -104,4 +104,4 @@ AUTHOR VERSION - 2.56 + 2.57 diff --git a/t/run.t b/t/run.t index c504d6c..766d119 100644 --- a/t/run.t +++ b/t/run.t @@ -8,7 +8,7 @@ use Data::Dumper; -use Test::More tests => 71; +use Test::More tests => 72; #use Test::More qw(no_plan); # ahem, we deliver the test code with a local copy of @@ -742,3 +742,9 @@ is($hash54{val}, qq(\\\$notavar:\\blah), "check -NoEscape"); my $cfg55 = new Config::General( -ConfigFile => "t/cfg.55" ); my %hash55 = $cfg55->getall(); is($hash55{b}, "nochop", "check continuation followed by empty line"); + +my $cfg56 = Config::General->new(); +eval { + $cfg56->save_file("t/56.out", { "new\nline" => 9, "brack 8 }); +}; +ok($@, "catch special chars in keys");