Skip to content

Commit

Permalink
relaxed name handling in Mojo::Headers a little
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 19, 2014
1 parent 6d80fb7 commit 6c18df3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

4.94 2014-04-19
- Relaxed name handling in Mojo::Headers a little.

4.93 2014-04-13
- Fixed bug where Mojolicious::Static would not use the correct default MIME
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -99,7 +99,7 @@ sub parse {
}

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

# Multiline
elsif (@$headers && $line =~ s/^\s+//) { push @{$headers->[-1]}, $line }
Expand Down
7 changes: 5 additions & 2 deletions t/mojo/headers.t
Expand Up @@ -154,13 +154,15 @@ Foo: first
second
third
Content-Type: text/plain
Foo Bar: baz
Foo: first again
second again
EOF
ok $headers->is_finished, 'parser is finished';
my $multi = [['first', 'second', 'third'], ['first again', 'second again']];
$hash = {'Content-Type' => [['text/plain']], Foo => $multi};
$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'),
Expand All @@ -170,7 +172,8 @@ 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 6c18df3

Please sign in to comment.