From d9e245af966d87164bc0322bf1fc498e1d891b08 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Tue, 17 Jan 2017 10:56:43 +0100 Subject: Fix parsing of .info files with trailing whitespace. This fixes #54. --- README.md | 1 + SBO-Lib/Changes | 2 ++ SBO-Lib/lib/SBO/Lib/Info.pm | 2 +- t/32-info.t | 8 ++++++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 17adb95..01521cf 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ## Changes * 2.2 - Unreleased + * Bugfix for parsing .info files with trailing whitespace after a value #54 * 2.1 - 2017-01-14 * Internals: diff --git a/SBO-Lib/Changes b/SBO-Lib/Changes index cf4c59e..2f1aeaa 100644 --- a/SBO-Lib/Changes +++ b/SBO-Lib/Changes @@ -1,4 +1,6 @@ 2.2 - Unreleased + * Bugfix for parsing .info files with trailing whitespace after a value + (https://github.com/pink-mist/sbotools/issues/54) 2.1 - 2017-01-14 * Internals: diff --git a/SBO-Lib/lib/SBO/Lib/Info.pm b/SBO-Lib/lib/SBO/Lib/Info.pm index 9d90ac3..1ff3216 100644 --- a/SBO-Lib/lib/SBO/Lib/Info.pm +++ b/SBO-Lib/lib/SBO/Lib/Info.pm @@ -216,7 +216,7 @@ sub parse_info { my $pos = 0; my %ret; - while ($info_str =~ /\G([A-Za-z0-9_]+)="([^"]*)"\n/g) { + while ($info_str =~ /\G([A-Za-z0-9_]+)="([^"]*)"\s*\n/g) { my $key = $1; my @val = split " ", $2; @val = '' unless @val; diff --git a/t/32-info.t b/t/32-info.t index be39db1..8b74e4b 100644 --- a/t/32-info.t +++ b/t/32-info.t @@ -9,7 +9,7 @@ use FindBin '$RealBin'; use lib "$RealBin/../SBO-Lib/lib"; use SBO::Lib 'parse_info'; -plan tests => 13; +plan tests => 16; my %parse = parse_info(<<"END"); FOO="bar" @@ -18,6 +18,7 @@ baz" BAZ="barf foof bazf" QUUX="finf" +FLAR_f="trailing whitespace" END is ($parse{FOO}[0], 'bar', 'bar value gotten from FOO key'); @@ -32,5 +33,8 @@ is ($parse{BAZ}[2], 'bazf', 'bazf value gotten from BAZ key'); is ($parse{BAZ}[3], undef, 'BAZ key has correct length'); is ($parse{QUUX}[0], 'finf', 'finf value gotten from QUUX key'); is ($parse{QUUX}[1], undef, 'QUUX key has correct length'); -delete @parse{qw/ FOO BAR BAZ QUUX /}; +is ($parse{FLAR_f}[0], 'trailing', 'trailing value gotten from FLAR_f key'); +is ($parse{FLAR_f}[1], 'whitespace', 'whitespace value gotten from FLAR_f key'); +is ($parse{FLAR_f}[2], undef, 'FLAR_f key has correct length'); +delete @parse{qw/ FOO BAR BAZ QUUX FLAR_f /}; is (scalar %parse, 0, 'no additional keys were parsed'); -- cgit v1.2.3