diff --git a/lib/CPAN/Changes.pm b/lib/CPAN/Changes.pm index 1c3c7ac..91344f4 100644 --- a/lib/CPAN/Changes.pm +++ b/lib/CPAN/Changes.pm @@ -71,9 +71,11 @@ sub load_string { next if $l =~ m{^\s*$}; - if ( !$indent ) { - $l =~ m{^(\s+)}; - $indent = '\s' x length $1; + if ( !defined $indent ) { + $indent + = $l =~ m{^(\s+)} + ? '\s' x length $1 + : ''; } $l =~ s{^$indent}{}; diff --git a/t/corpus/no-leading-space-for-change.changes b/t/corpus/no-leading-space-for-change.changes new file mode 100644 index 0000000..22175ec --- /dev/null +++ b/t/corpus/no-leading-space-for-change.changes @@ -0,0 +1,3 @@ +0.01 2010-06-16 +- Initial release + This line is part of the first diff --git a/t/read_no-leading-space-for-change.t b/t/read_no-leading-space-for-change.t new file mode 100644 index 0000000..6638b9f --- /dev/null +++ b/t/read_no-leading-space-for-change.t @@ -0,0 +1,31 @@ +use strict; +use warnings; + +use Test::More; + +use_ok( 'CPAN::Changes' ); + +my $changes = CPAN::Changes->load( 't/corpus/no-leading-space-for-change.changes' ); + +isa_ok( $changes, 'CPAN::Changes' ); +is( $changes->preamble, '', 'no preamble' ); + +my @releases = $changes->releases; + +is( scalar @releases, 1, 'has 1 release' ); +isa_ok( $releases[ 0 ], 'CPAN::Changes::Release' ); +is( $releases[ 0 ]->version, '0.01', 'version' ); +is( $releases[ 0 ]->date, '2010-06-16', 'date' ); +is_deeply( + $releases[ 0 ]->changes, + { '' => [ "Initial release This line is part of the first" ] }, + 'full changes' +); +is_deeply( [ $releases[ 0 ]->groups ], [ '' ], 'only the main group' ); +is_deeply( + $releases[ 0 ]->changes( '' ), + [ "Initial release This line is part of the first" ], + 'one change line' +); + +done_testing;