From: Sebastian Riedel Date: Sat, 19 Nov 2005 22:04:56 +0000 (+0000) Subject: Updated uri_for to accept undef actions X-Git-Tag: 5.7099_04~860 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=d3e7a648cc29a8b45ddcd4ef731e3f9b0b4f919c;hp=d30e01db2092a05fca10e0efbacbb71d4554a468 Updated uri_for to accept undef actions --- diff --git a/Changes b/Changes index fe3a648..c2bc129 100644 --- 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 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 904693b..5f47a65 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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 diff --git a/t/unit_core_uri_for.t b/t/unit_core_uri_for.t index 4b02021..c6726f6 100644 --- a/t/unit_core_uri_for.t +++ b/t/unit_core_uri_for.t @@ -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' );