Skip to content

Commit

Permalink
fix punycode bug in Mojo::URL (closes #856)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 22, 2015
1 parent ed6ffa5 commit 58cd44e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -9,6 +9,7 @@
whitespace.
- Improved rendering of built-in templates to show actual template names in
log messages.
- Fixed punycode bug in Mojo::URL.
- Fixed "0" value bug in Mojo::JSON::Pointer.

6.24 2015-10-13
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/URL.pm
Expand Up @@ -54,7 +54,7 @@ sub ihost {

# Decode
return $self->host(join '.',
map { /^xn--/ ? punycode_decode $_ : $_ } split(/\./, shift, -1))
map { /^xn--(.+)$/ ? punycode_decode $1 : $_ } split(/\./, shift, -1))
if @_;

# Check if host needs to be encoded
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/url.t
Expand Up @@ -342,6 +342,11 @@ is $url->port, 3000, 'right port';
is $url->path, '/foo', 'right path';
is "$url", 'http://xn--bcher-kva.xn--bcher-kva.xn--bcher-kva.ch:3000/foo',
'right format';
$url = Mojo::URL->new->scheme('http')->ihost('xn--n3h.xn--n3h.net');
is $url->scheme, 'http', 'right scheme';
is $url->host, '☃.☃.net', 'right host';
is $url->ihost, 'xn--n3h.xn--n3h.net', 'right internationalized host';
is "$url", 'http://xn--n3h.xn--n3h.net', 'right format';

# IDNA (escaped userinfo and host)
$url = Mojo::URL->new('https://%E2%99%A5:%E2%99%A5@kr%E4ih.com:3000');
Expand Down

0 comments on commit 58cd44e

Please sign in to comment.