Skip to content

Commit

Permalink
fixed IDNA support in Mojo::UserAgent::CookieJar
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 12, 2013
1 parent 3810a31 commit 68b0d5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@
- Improved documentation.
- Improved tests.
- Fixed domain and path detection bugs in Mojo::UserAgent::CookieJar.
- Fixed IDNA support in Mojo::UserAgent::CookieJar.

3.77 2013-01-12
- Added support for advanced binary WebSocket message tests to Test::Mojo.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -61,7 +61,7 @@ sub find {
my ($self, $url) = @_;

# Look through the jar
return unless my $domain = lc($url->host // '');
return unless my $domain = lc($url->ihost // '');
my $path = $url->path->to_abs_string;
my @found;
while ($domain =~ /[^.]+\.[^.]+|localhost$/) {
Expand Down
24 changes: 12 additions & 12 deletions t/mojo/cookiejar.t
Expand Up @@ -118,7 +118,7 @@ is $cookies[1]->name, 'foo', 'right name';
is $cookies[1]->value, 'bar', 'right value';
is $cookies[2], undef, 'no third cookie';

# Random top-level domain
# Random top-level domain and IDNA
$jar = Mojo::UserAgent::CookieJar->new;
$jar->add(
Mojo::Cookie::Response->new(
Expand All @@ -128,29 +128,29 @@ $jar->add(
value => 'bar'
),
Mojo::Cookie::Response->new(
domain => 'kraih.com',
domain => 'xn--bcher-kva.com',
path => '/foo',
name => 'bar',
value => 'baz'
)
);
@cookies = $jar->find(Mojo::URL->new('http://kraih.com/foo'));
@cookies = $jar->find(Mojo::URL->new('http://bücher.com/foo'));
is $cookies[0]->name, 'bar', 'right name';
is $cookies[0]->value, 'baz', 'right value';
is $cookies[1], undef, 'no second cookie';
@cookies = $jar->find(Mojo::URL->new('http://kraih.com/foo'));
@cookies = $jar->find(Mojo::URL->new('http://bücher.com/foo'));
is $cookies[0]->name, 'bar', 'right name';
is $cookies[0]->value, 'baz', 'right value';
is $cookies[1], undef, 'no second cookie';
@cookies = $jar->all;
is $cookies[0]->domain, 'com', 'right domain';
is $cookies[0]->path, '/foo', 'right path';
is $cookies[0]->name, 'foo', 'right name';
is $cookies[0]->value, 'bar', 'right value';
is $cookies[1]->domain, 'kraih.com', 'right domain';
is $cookies[1]->path, '/foo', 'right path';
is $cookies[1]->name, 'bar', 'right name';
is $cookies[1]->value, 'baz', 'right value';
is $cookies[0]->domain, 'com', 'right domain';
is $cookies[0]->path, '/foo', 'right path';
is $cookies[0]->name, 'foo', 'right name';
is $cookies[0]->value, 'bar', 'right value';
is $cookies[1]->domain, 'xn--bcher-kva.com', 'right domain';
is $cookies[1]->path, '/foo', 'right path';
is $cookies[1]->name, 'bar', 'right name';
is $cookies[1]->value, 'baz', 'right value';
is $cookies[2], undef, 'no third cookie';

# Huge cookie
Expand Down

0 comments on commit 68b0d5a

Please sign in to comment.