Skip to content

Commit

Permalink
and more parse_header bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 1, 2013
1 parent 36e95c6 commit df3d5e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -133,7 +133,7 @@ sub parse_header {
my $str = shift;
my (@tree, @token);
while ($str =~ s/^\s*([^=;, ]+)\s*//) {
while ($str =~ s/^[,;\s]*([^=;, ]+)\s*//) {
push @token, $1, undef;
$token[-1] = unquote($1)
if $str =~ s/^=\s*("(?:\\\\|\\"|[^"])*"|[^;, ]*)\s*//;
Expand Down
6 changes: 5 additions & 1 deletion t/mojo/util.t
Expand Up @@ -60,6 +60,10 @@ is get_line(\$buffer), undef, 'no line';

# parse_header
is_deeply parse_header(''), [], 'right result';
is_deeply parse_header(',,foo,, ,bar'), [['foo', undef], ['bar', undef]],
'right result';
is_deeply parse_header(';;foo; ; ;bar'), [['foo', undef, 'bar', undef]],
'right result';
is_deeply parse_header('foo=;bar=""'), [['foo', '', 'bar', '']],
'right result';
is_deeply parse_header('foo=bar baz=yada'), [['foo', 'bar', 'baz', 'yada']],
Expand All @@ -69,7 +73,7 @@ is_deeply parse_header('foo,bar,baz'),
is_deeply parse_header('f "o" o , ba r'),
[['f', undef, '"o"', undef, 'o', undef], ['ba', undef, 'r', undef]],
'right result';
is_deeply parse_header('foo="b a\" r\"\\\\"'), [['foo', 'b a" r"\\']],
is_deeply parse_header('foo="b,; a\" r\"\\\\"'), [['foo', 'b,; a" r"\\']],
'right result';
is_deeply parse_header('foo = "b a\" r\"\\\\"'), [['foo', 'b a" r"\\']],
'right result';
Expand Down

0 comments on commit df3d5e0

Please sign in to comment.