Skip to content

Commit

Permalink
fixed continuation line handling in Mojo::Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 30, 2014
1 parent e3b5881 commit 1b99cbe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.01 2014-05-30
- Fixed continuation line handling in Mojo::Headers.

5.0 2014-05-29
- Code name "Tiger Face", this is a major release.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -63,7 +63,7 @@ sub header {
return $self->remove($name)->add($name, @_) if @_;

return undef unless my $headers = $self->{headers}{lc $name};
return join ', ', map { join ', ', @$_ } @$headers;
return join ', ', map { join ' ', @$_ } @$headers;
}

sub is_finished { (shift->{state} // '') eq 'finished' }
Expand Down
12 changes: 6 additions & 6 deletions t/mojo/headers.t
Expand Up @@ -125,9 +125,9 @@ is $headers->to_string,
. "X-Test: 25\x0d\x0a 26", 'right format';
is_deeply $headers->to_hash(1),
{'X-Test' => [[23, 24], ['single line'], [25, 26]]}, 'right structure';
is_deeply $headers->to_hash, {'X-Test' => '23, 24, single line, 25, 26'},
is_deeply $headers->to_hash, {'X-Test' => '23 24, single line, 25 26'},
'right structure';
is $headers->header('X-Test'), "23, 24, single line, 25, 26", 'right format';
is $headers->header('X-Test'), "23 24, single line, 25 26", 'right format';

# Parse headers
$headers = Mojo::Headers->new;
Expand Down Expand Up @@ -163,14 +163,14 @@ $hash = {
'Foo Bar' => [['baz']]
};
is_deeply $headers->to_hash(1), $hash, 'right structure';
is scalar $headers->header('Foo'),
'first, second, third, first again, second ":again"', 'right value';
is $headers->header('Foo'), '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 Expand Up @@ -208,7 +208,7 @@ $headers = Mojo::Headers->new;
$headers->from_hash(
{'X-Test' => [[23, 24], ['single line'], [25, 26]], 'X-Test2' => 'foo'});
$hash = $headers->to_hash;
is $hash->{'X-Test'}, '23, 24, single line, 25, 26', 'right value';
is $hash->{'X-Test'}, '23 24, single line, 25 26', 'right value';
is $hash->{'X-Test2'}, 'foo', 'right value';
$hash = $headers->to_hash(1);
is_deeply $hash->{'X-Test'}, [[23, 24], ['single line'], [25, 26]],
Expand Down

0 comments on commit 1b99cbe

Please sign in to comment.