| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This script attempts to reproduce: |
| 4 |
# http://rt.cpan.org/Public/Bug/Display.html?id=51445 |
| 5 |
# |
| 6 |
# #51445: 2.52 CRLF-ini with multi-value params fails under Linux |
| 7 |
|
| 8 |
use Test::More tests => 20; |
| 9 |
|
| 10 |
use strict; |
| 11 |
use warnings; |
| 12 |
|
| 13 |
use Config::IniFiles; |
| 14 |
|
| 15 |
use File::Spec; |
| 16 |
|
| 17 |
my $ini_filename = |
| 18 |
File::Spec->catfile( File::Spec->curdir(), "t", 'test25.ini' ); |
| 19 |
|
| 20 |
{ |
| 21 |
|
| 22 |
# being pedantic, we don't take line breaks from this or an external file for granted |
| 23 |
my $sample_ini = "<eol> |
| 24 |
<sol># this is a sample file for testing the proper detection of line endings in Config::IniFiles<eol> |
| 25 |
<sol><eol> |
| 26 |
<sol>[single values]<eol> |
| 27 |
<sol>firstval = first value<eol> |
| 28 |
<sol>secondval=2nd<eol> |
| 29 |
<sol><eol> |
| 30 |
<sol># in v2.52 on linux multi values with crlf lines are failing<eol> |
| 31 |
<sol>[multi value]<eol> |
| 32 |
<sol>Paths=<<EOT<eol> |
| 33 |
<sol>path1<eol> |
| 34 |
<sol>path2<eol> |
| 35 |
<sol>EOT<eol> |
| 36 |
<sol><eol> |
| 37 |
<sol>"; |
| 38 |
|
| 39 |
foreach my $lf ( ( "\x0d\x0a", "\x0d", "\x0a", "\x15", "\n" ) ) |
| 40 |
{ |
| 41 |
my $ini = $sample_ini; |
| 42 |
$ini =~ s/<eol>[^<]*<sol>/$lf/g; |
| 43 |
|
| 44 |
open my $INI, '>', $ini_filename or die $!; |
| 45 |
binmode $INI; |
| 46 |
print {$INI} $ini; |
| 47 |
close $INI; |
| 48 |
|
| 49 |
my $lf_print = |
| 50 |
join( '', map { sprintf '\x%0.2x', ord $_ } split( //, $lf ) ); |
| 51 |
|
| 52 |
my $cfg = Config::IniFiles->new( -file => $ini_filename ); |
| 53 |
|
| 54 |
# TEST |
| 55 |
ok( $cfg, "Loading from a '$lf_print'-separated file" ); |
| 56 |
|
| 57 |
# TEST |
| 58 |
my $value = $cfg->val( 'single values', 'firstval' ); |
| 59 |
is( $value, 'first value', |
| 60 |
"Reading a single value from a '$lf_print'-separated file" ); |
| 61 |
|
| 62 |
# TEST |
| 63 |
$value = $cfg->val( 'single values', 'secondval' ); |
| 64 |
is( $value, '2nd', |
| 65 |
"Reading a single value from a '$lf_print'-separated file" ); |
| 66 |
|
| 67 |
my @vals = $cfg->val( "multi value", "Paths" ); |
| 68 |
|
| 69 |
# TEST |
| 70 |
is_deeply( |
| 71 |
\@vals, |
| 72 |
[ 'path1', 'path2' ], |
| 73 |
"Reading a multiple value from a '$lf_print'-separated file", |
| 74 |
); |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
unlink($ini_filename); |