Updated uri_for to accept undef actions
Sebastian Riedel [Sat, 19 Nov 2005 22:04:56 +0000 (22:04 +0000)]
Changes
lib/Catalyst.pm
t/unit_core_uri_for.t

diff --git a/Changes b/Changes
index fe3a648..c2bc129 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 This file documents the revision history for Perl extension Catalyst.
 
 5.57
+        - Updated uri_for to accept undef actions
         - Switched to Module::Install
         - Renamed tests for easier editing
         - Reformatted documentation
index 904693b..5f47a65 100644 (file)
@@ -674,8 +674,11 @@ sub uri_for {
 
     # join args with '/', or a blank string
     my $args = ( scalar @args ? '/' . join( '/', @args ) : '' );
-    return URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ),
-        $base )->canonical;
+    $args =~ s/^\/// unless $path;
+    my $res =
+      URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ), $base )
+      ->canonical;
+    $res;
 }
 
 =head2 $c->welcome_message
index 4b02021..c6726f6 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 use Test::MockObject;
 use URI;
 
@@ -26,6 +26,13 @@ is(
     'URI for relative path'
 );
 
+is(
+    Catalyst::uri_for( $context, '', 'arg1', 'arg2' )->as_string,
+    'http://127.0.0.1/foo/yada/arg1/arg2',
+    'URI for undef action with args'
+);
+
+
 is( Catalyst::uri_for( $context, '../quux' )->as_string,
     'http://127.0.0.1/foo/quux', 'URI for relative dot path' );