Skip to content

Commit

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

3.86 2013-02-19
3.86 2013-02-20
- Improved portability of Mojo::Asset::File tests.
- Improved documentation.
- Improved tests. (jberger, sri)
- Fixed small domain detection bug in Mojo::UserAgent::CookieJar.
- Fixed comment lines in Mojo::Template to cover the whole line.

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

# Validate path
Expand Down
25 changes: 23 additions & 2 deletions t/mojo/cookiejar.t
Expand Up @@ -382,6 +382,27 @@ 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';

# Extract and inject cookies with IP address
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://213.133.102.53/perldoc/Mojolicious');
$tx->res->cookies(
Mojo::Cookie::Response->new(
name => 'foo',
value => 'valid',
domain => '213.133.102.53'
),
Mojo::Cookie::Response->new(name => 'bar', value => 'too')
);
$jar->extract($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://213.133.102.53/perldoc/Mojolicious');
$jar->inject($tx);
is $tx->req->cookie('foo')->name, 'foo', 'right name';
is $tx->req->cookie('foo')->value, 'valid', 'right value';
is $tx->req->cookie('bar')->name, 'bar', 'right name';
is $tx->req->cookie('bar')->value, 'too', 'right value';

# Extract cookies with invalid domain
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
Expand All @@ -408,8 +429,8 @@ $tx->req->url->parse('http://213.133.102.53/perldoc/Mojolicious');
$tx->res->cookies(
Mojo::Cookie::Response->new(
name => 'foo',
value => 'invalid',
domain => '213.133.102.53'
value => 'valid',
domain => '.213.133.102.53'
),
Mojo::Cookie::Response->new(
name => 'foo',
Expand Down

0 comments on commit 87eff01

Please sign in to comment.