1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
Description: Improve RFC3986 compliance of Mojo::Path.
Origin: backport, commit: 748ef373291dd342c18a
Forwarded: no
Author: Salvatore Bonaccorso <carnil@debian.org>
Last-Update: 2011-04-16
--- a/lib/Mojo/Path.pm
+++ b/lib/Mojo/Path.pm
@@ -92,8 +92,11 @@
my @parts;
for my $part (split '/', $path) {
- # Garbage
- next unless length $part;
+ # Empty parts before the first are garbage
+ next unless length $part or scalar @parts;
+
+ # Empty parts behind the first are ok
+ $part = '' unless defined $part;
# Store
push @parts, $part;
--- a/t/mojo/url.t
+++ b/t/mojo/url.t
@@ -7,7 +7,7 @@
use utf8;
-use Test::More tests => 111;
+use Test::More tests => 117;
use Mojo::ByteStream 'b';
@@ -236,3 +236,17 @@
. '%D1%88%D0%B0%D1%80%D0%B8%D1%84%D1%83%D0%BB%D0%B8%D0%BD',
'right format'
);
+
+# Empty path elements
+$url = Mojo::URL->new('http://kraih.com/foo//bar/23/');
+$url->base->parse('http://kraih.com/');
+is($url->is_abs, 1);
+is($url->to_rel, '/foo//bar/23/');
+$url = Mojo::URL->new('http://kraih.com//foo//bar/23/');
+$url->base->parse('http://kraih.com/');
+is($url->is_abs, 1);
+is($url->to_rel, '/foo//bar/23/');
+$url = Mojo::URL->new('http://kraih.com/foo///bar/23/');
+$url->base->parse('http://kraih.com/');
+is($url->is_abs, 1);
+is($url->to_rel, '/foo///bar/23/');
--- a/t/mojox/routes/routes.t
+++ b/t/mojox/routes/routes.t
@@ -347,8 +347,8 @@
$m = MojoX::Routes::Match->new($tx)->match($r);
is($m->stack->[0]->{controller}, 'wild');
is($m->stack->[0]->{action}, 'card');
-is($m->stack->[0]->{wildcard}, 'http:/www.google.com');
-is($m->url_for, '/wildcards/1/http:/www.google.com');
+is($m->stack->[0]->{wildcard}, 'http://www.google.com');
+is($m->url_for, '/wildcards/1/http://www.google.com');
is(@{$m->stack}, 1);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->method('GET');
@@ -357,7 +357,7 @@
is($m->stack->[0]->{controller}, 'wild');
is($m->stack->[0]->{action}, 'card');
is($m->stack->[0]->{wildcard}, 'http://www.google.com');
-is($m->url_for, '/wildcards/1/http:/www.google.com');
+is($m->url_for, '/wildcards/1/http://www.google.com');
is(@{$m->stack}, 1);
# Format
|