-
-
Save anonymous/589722ab8b361769e9f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/URL.pm b/lib/Mojo/URL.pm | |
index 7249411..e448b52 100644 | |
--- a/lib/Mojo/URL.pm | |
+++ b/lib/Mojo/URL.pm | |
@@ -4,7 +4,8 @@ use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1; | |
use Mojo::Parameters; | |
use Mojo::Path; | |
-use Mojo::Util qw(punycode_decode punycode_encode url_escape url_unescape); | |
+use Mojo::Util | |
+ qw(decode encode punycode_decode punycode_encode url_escape url_unescape); | |
has base => sub { Mojo::URL->new }; | |
has [qw(fragment host port scheme userinfo)]; | |
@@ -17,7 +18,10 @@ sub authority { | |
return $self unless defined(my $authority = shift); | |
# Userinfo | |
- $authority =~ s/^([^\@]+)\@// and $self->userinfo(url_unescape $1); | |
+ if ($authority =~ s/^([^\@]+)\@//) { | |
+ my $info = url_unescape $1; | |
+ $self->userinfo(decode('UTF-8', $info) // $info); | |
+ } | |
# Port | |
$authority =~ s/:(\d+)$// and $self->port($1); | |
@@ -30,6 +34,7 @@ sub authority { | |
# Build authority | |
return undef unless defined(my $authority = $self->host_port); | |
return $authority unless my $info = $self->userinfo; | |
+ $info = encode 'UTF-8', $info; | |
return url_escape($info, '^A-Za-z0-9\-._~!$&\'()*+,;=:') . '@' . $authority; | |
} | |
diff --git a/t/mojo/url.t b/t/mojo/url.t | |
index 4ea8c49..3525206 100644 | |
--- a/t/mojo/url.t | |
+++ b/t/mojo/url.t | |
@@ -340,20 +340,22 @@ is "$url", 'http://xn--bcher-kva.xn--bcher-kva.xn--bcher-kva.ch:3000/foo', | |
'right format'; | |
# IDNA (escaped userinfo and host) | |
-$url = Mojo::URL->new('https://foo:b%E4r@kr%E4ih.com:3000'); | |
-is $url->host, "kr\xe4ih.com", 'right host'; | |
-is $url->ihost, 'xn--krih-moa.com', 'right internationalized host'; | |
-is $url->port, 3000, 'right port'; | |
-is "$url", 'https://foo:b%E4r@xn--krih-moa.com:3000', 'right format'; | |
+$url = Mojo::URL->new('https://%E2%99%A5:%E2%99%A5@kr%E4ih.com:3000'); | |
+is $url->userinfo, '♥:♥', 'right userinfo'; | |
+is $url->host, "kr\xe4ih.com", 'right host'; | |
+is $url->ihost, 'xn--krih-moa.com', 'right internationalized host'; | |
+is $url->port, 3000, 'right port'; | |
+is "$url", 'https://%E2%99%A5:%E2%99%A5@xn--krih-moa.com:3000', 'right format'; | |
# IDNA (snowman) | |
-$url = Mojo::URL->new('http://☃.net/'); | |
-ok $url->is_abs, 'is absolute'; | |
-is $url->scheme, 'http', 'right scheme'; | |
-is $url->host, '☃.net', 'right host'; | |
-is $url->ihost, 'xn--n3h.net', 'right internationalized host'; | |
-is $url->path, '/', 'right path'; | |
-is "$url", 'http://xn--n3h.net/', 'right format'; | |
+$url = Mojo::URL->new('http://☃:☃@☃.net/'); | |
+ok $url->is_abs, 'is absolute'; | |
+is $url->scheme, 'http', 'right scheme'; | |
+is $url->userinfo, '☃:☃', 'right userinfo'; | |
+is $url->host, '☃.net', 'right host'; | |
+is $url->ihost, 'xn--n3h.net', 'right internationalized host'; | |
+is $url->path, '/', 'right path'; | |
+is "$url", 'http://%E2%98%83:%E2%98%83@xn--n3h.net/', 'right format'; | |
# IRI/IDNA | |
$url = Mojo::URL->new('http://☃.net/♥/?q=♥☃'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment