Test and fix for a case which caused uri_for to generate a double slash at the start...
Tomas Doran [Sun, 7 Dec 2008 18:31:30 +0000 (18:31 +0000)]
lib/Catalyst.pm
t/unit_core_uri_for.t

index 8cb6866..63c2fb7 100644 (file)
@@ -1077,7 +1077,7 @@ sub uri_for {
     # join args with '/', or a blank string
     my $args = join('/', grep { defined($_) } @args);
     $args =~ s/\?/%3F/g; # STUPID STUPID SPECIAL CASE
-    $args =~ s!^/!!;
+    $args =~ s!^/+!!;
     my $base = $c->req->base;
     my $class = ref($base);
     $base =~ s{(?<!/)$}{/};
index c767ff2..fb5ea1e 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 15;
+use Test::More tests => 16;
 use URI;
 
 use_ok('Catalyst');
@@ -103,3 +103,8 @@ is(
     is( $warnings, 0, "no warnings emitted" );
 }
 
+# Test with parameters '/', 'foo', 'bar' - should not generate a //
+is( Catalyst::uri_for( $context, qw| / foo bar | )->as_string,
+    'http://127.0.0.1/foo/bar', 'uri is /foo/bar, not //foo/bar'
+);
+