Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
made Mojo::Headers a little more resilient
  • Loading branch information
kraih committed Apr 19, 2014
1 parent 6c18df3 commit 5dce091
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -99,7 +99,7 @@ sub parse {
}

# New header
if ($line =~ /^([^:]+)\s*:\s*(.*)$/) { push @$headers, $1, [$2] }
if ($line =~ /^(\S[^:]+)\s*:\s*(.*)$/) { push @$headers, $1, [$2] }

# Multiline
elsif (@$headers && $line =~ s/^\s+//) { push @{$headers->[-1]}, $line }
Expand Down
8 changes: 4 additions & 4 deletions t/mojo/headers.t
Expand Up @@ -156,23 +156,23 @@ Foo: first
Content-Type: text/plain
Foo Bar: baz
Foo: first again
second again
second ":again"
EOF
ok $headers->is_finished, 'parser is finished';
my $multi = [['first', 'second', 'third'], ['first again', 'second again']];
my $multi = [['first', 'second', 'third'], ['first again', 'second ":again"']];
$hash = {'Content-Type' => [['text/plain']], Foo => $multi,
'Foo Bar' => [['baz']]};
is_deeply $headers->to_hash(1), $hash, 'right structure';
is_deeply [$headers->header('Foo')], $multi, 'right structure';
is scalar $headers->header('Foo'),
'first, second, third, first again, second again', 'right value';
'first, second, third, first again, second ":again"', 'right value';
$headers = Mojo::Headers->new->parse($headers->to_string . "\x0d\x0a\x0d\x0a");
ok $headers->is_finished, 'parser is finished';
is_deeply $headers->to_hash(1), $hash, 'successful roundtrip';
$hash = {
'Content-Type' => 'text/plain',
Foo => 'first, second, third, first again, second again',
Foo => 'first, second, third, first again, second ":again"',
'Foo Bar' => 'baz'
};
is_deeply $headers->to_hash, $hash, 'right structure';
Expand Down

0 comments on commit 5dce091

Please sign in to comment.