diff --git a/Changes b/Changes index a208692930..fb187f44ea 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ 7.18 2017-01-11 - Fixed support for relative %INC paths in Mojo::Home. + - Fixed a bug in Mojo::URL where invalid fragment strings could be generated. 7.17 2017-01-11 - Fixed Windows bugs in Mojo::File. (kmx) diff --git a/lib/Mojo/URL.pm b/lib/Mojo/URL.pm index 85030cd9d4..8d91cf6d46 100644 --- a/lib/Mojo/URL.pm +++ b/lib/Mojo/URL.pm @@ -166,7 +166,7 @@ sub to_string { # Fragment return $url unless defined(my $fragment = $self->fragment); return $url . '#' . url_escape encode('UTF-8', $fragment), - '^A-Za-z0-9\-._~!$&\'()*+,;=%:@/?'; + '^A-Za-z0-9\-._~!$&\'()*+,;=:@/?'; } sub username { (shift->userinfo // '') =~ /^([^:]+)/ ? $1 : undef } diff --git a/t/mojo/request.t b/t/mojo/request.t index 98b5504f05..5f510375c8 100644 --- a/t/mojo/request.t +++ b/t/mojo/request.t @@ -2098,7 +2098,7 @@ $req->parse("HTTP/1.1\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; is $req->method, 'GET', 'right method'; is $req->version, '1.1', 'right version'; -is $req->url, "/#09azAZ!\$%&\'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~%C3%9F", +is $req->url, "/#09azAZ!\$%25&\'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~%C3%9F", 'right URL'; # Abstract methods diff --git a/t/mojo/url.t b/t/mojo/url.t index 79735880c4..d22ba60634 100644 --- a/t/mojo/url.t +++ b/t/mojo/url.t @@ -26,22 +26,22 @@ is $url->path, '/x/index.html', 'right path'; is $url->query, 'monkey=biz&foo=1', 'right query'; is $url->path_query, '/x/index.html?monkey=biz&foo=1', 'right path and query'; is $url->fragment, '/!%?@3', 'right fragment'; -is "$url", 'https://example.com:8080/x/index.html?monkey=biz&foo=1#/!%?@3', +is "$url", 'https://example.com:8080/x/index.html?monkey=biz&foo=1#/!%25?@3', 'right format'; $url->path('/index.xml'); -is "$url", 'https://example.com:8080/index.xml?monkey=biz&foo=1#/!%?@3', +is "$url", 'https://example.com:8080/index.xml?monkey=biz&foo=1#/!%25?@3', 'right format'; # Advanced userinfo and fragment roundtrip $url = Mojo::URL->new( - 'ws://AZaz09-._~!$&\'()*+,;=:@localhost#AZaz09-._~!$&\'()*+,;=%:@/?'); -is $url->scheme, 'ws', 'right scheme'; -is $url->userinfo, 'AZaz09-._~!$&\'()*+,;=:', 'right userinfo'; -is $url->username, 'AZaz09-._~!$&\'()*+,;=', 'right username'; -is $url->password, '', 'right password'; -is $url->host, 'localhost', 'right host'; -is $url->fragment, 'AZaz09-._~!$&\'()*+,;=%:@/?', 'right fragment'; -is "$url", 'ws://localhost#AZaz09-._~!$&\'()*+,;=%:@/?', 'right format'; + 'ws://AZaz09-._~!$&\'()*+,;=:@localhost#AZaz09-._~!$&\'()*+,;=:@/?'); +is $url->scheme, 'ws', 'right scheme'; +is $url->userinfo, 'AZaz09-._~!$&\'()*+,;=:', 'right userinfo'; +is $url->username, 'AZaz09-._~!$&\'()*+,;=', 'right username'; +is $url->password, '', 'right password'; +is $url->host, 'localhost', 'right host'; +is $url->fragment, 'AZaz09-._~!$&\'()*+,;=:@/?', 'right fragment'; +is "$url", 'ws://localhost#AZaz09-._~!$&\'()*+,;=:@/?', 'right format'; # Parameters $url = Mojo::URL->new(