Skip to content

Instantly share code, notes, and snippets.

Created September 3, 2010 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/563843 to your computer and use it in GitHub Desktop.
Save anonymous/563843 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Path.pm b/lib/Mojo/Path.pm
index a96bead..6bf4515 100644
--- a/lib/Mojo/Path.pm
+++ b/lib/Mojo/Path.pm
@@ -87,8 +87,11 @@ sub parse {
my @parts;
for my $part (split '/', $path) {
- # Garbage
- next unless length $part;
+ # Empty parts before the first part are garbage
+ next unless length $part or scalar @parts;
+
+ # Empty parts behind the first are ok though
+ $part ||= '';
# Store
push @parts, b($part)->url_unescape($Mojo::URL::PCHAR)->to_string;
diff --git a/t/mojo/url.t b/t/mojo/url.t
index b16a7c8..df31a2a 100644
--- a/t/mojo/url.t
+++ b/t/mojo/url.t
@@ -5,7 +5,7 @@ use warnings;
use utf8;
-use Test::More tests => 113;
+use Test::More tests => 115;
# I don't want you driving around in a car you built yourself.
# You can sit there complaining, or you can knit me some seat belts.
@@ -240,3 +240,10 @@ is( "$url",
. '%D1%88%D0%B0%D1%80%D0%B8%D1%84%D1%83%D0%BB%D0%B8%D0%BD',
'right format'
);
+
+# Empty path element
+$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/');
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment