Skip to content

Commit

Permalink
fixed small domain detection bug in Mojo::UserAgent::CookieJar (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 26, 2013
1 parent 9a70130 commit b9901be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,7 +1,8 @@

3.88 2013-02-24
3.88 2013-02-26
- Improved documentation.
- Improved tests.
- Fixed small domain detection bug in Mojo::UserAgent::CookieJar.

3.87 2013-02-23
- Added deprecated function to Mojo::Util. (marcus)
Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -45,10 +45,9 @@ sub extract {
# Validate domain
my $host = lc $url->ihost;
my $domain = lc($cookie->domain // $host);
unless ($host eq $domain) {
$domain =~ s/^\.//;
next if $host !~ /\Q.$domain\E$/ || $host =~ /\.\d+$/;
}
$domain =~ s/^\.//;
next
if $host ne $domain && ($host !~ /\Q.$domain\E$/ || $host =~ /\.\d+$/);
$cookie->domain($domain);

# Validate path
Expand Down
15 changes: 14 additions & 1 deletion t/mojo/cookiejar.t
Expand Up @@ -376,6 +376,14 @@ is $tx->req->cookie('bar')->value, 'with', 'right value';
is $tx->req->cookie('baz')->name, 'baz', 'right name';
is $tx->req->cookie('baz')->value, 'with', 'right value';
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://bücher.COM/perldoc/Mojolicious/Lite');
$jar->inject($tx);
is $tx->req->cookie('foo'), undef, 'no cookie';
is $tx->req->cookie('bar')->name, 'bar', 'right name';
is $tx->req->cookie('bar')->value, 'with', 'right value';
is $tx->req->cookie('baz')->name, 'baz', 'right name';
is $tx->req->cookie('baz')->value, 'with', 'right value';
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://labs.bücher.COM/Perldoc');
$jar->inject($tx);
is $tx->req->cookie('foo'), undef, 'no cookie';
Expand Down Expand Up @@ -430,7 +438,12 @@ $tx->res->cookies(
Mojo::Cookie::Response->new(
name => 'foo',
value => 'valid',
domain => '.213.133.102.53'
domain => '213.133.102.53.'
),
Mojo::Cookie::Response->new(
name => 'foo',
value => 'valid',
domain => '.133.102.53'
),
Mojo::Cookie::Response->new(
name => 'foo',
Expand Down

0 comments on commit b9901be

Please sign in to comment.