( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
for my $value ( values %$params ) {
- my $isa_ref = ref $value;
- if( $isa_ref and $isa_ref ne 'ARRAY' ) {
- croak( "Non-array reference ($isa_ref) passed to uri_for()" );
+ for ( ref $value eq 'ARRAY' ? @$value : $value ) {
+ $_ = "$_";
+ utf8::encode( $_ );
}
- utf8::encode( $_ ) for grep { defined } $isa_ref ? @$value : $value;
};
# join args with '/', or a blank string
my( $self, $args ) = @_;
carp( 'No arguments passed to uri_with()' ) unless $args;
-
+
for my $value ( values %$args ) {
- my $isa_ref = ref $value;
- if( $isa_ref and $isa_ref ne 'ARRAY' ) {
- croak( "Non-array reference ($isa_ref) passed to uri_with()" );
+ for ( ref $value eq 'ARRAY' ? @$value : $value ) {
+ $_ = "$_";
+ utf8::encode( $_ );
}
- utf8::encode( $_ ) for grep{ defined } $isa_ref ? @$value : $value;
};
+
my $uri = $self->uri->clone;
$uri->query_form( {
$c->forward('TestApp::View::Dump::Request');\r
}\r
\r
+sub uri_with_object : Local {\r
+ my ( $self, $c ) = @_;\r
+\r
+ my $uri = $c->req->uri_with( { a => $c->req->base } );\r
+ my %query = $uri->query_form;\r
+ \r
+ $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );\r
+ \r
+ $c->forward('TestApp::View::Dump::Request');\r
+}\r
+\r
sub uri_with_utf8 : Local {\r
my ( $self, $c ) = @_;\r
\r
use FindBin;\r
use lib "$FindBin::Bin/lib";\r
\r
-use Test::More tests => 38;\r
+use Test::More tests => 41;\r
use Catalyst::Test 'TestApp';\r
use Catalyst::Request;\r
\r
is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
}\r
\r
+# test that uri_with replaces params (and preserves)\r
+{\r
+ ok( my $response = request('http://localhost/engine/request/uri/uri_with_object'), 'Request' );\r
+ ok( $response->is_success, 'Response Successful 2xx' );\r
+ is( $response->header( 'X-Catalyst-Param-a' ), 'http://localhost/', 'param "a" ok' );\r
+}\r
+\r
# test that uri_with is utf8 safe\r
{\r
ok( my $response = request("http://localhost/engine/request/uri/uri_with_utf8"), 'Request' );\r
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More tests => 10;
use URI;
use_ok('Catalyst');
'URI for undef action with query params in unicode'
);
+# test with object
+is(
+ Catalyst::uri_for( $context, 'quux', { param1 => $request->base } )->as_string,
+ 'http://127.0.0.1/foo/yada/quux?param1=http%3A%2F%2F127.0.0.1%2Ffoo',
+ 'URI for undef action with query param as object'
+);
+
$request->base( URI->new('http://localhost:3000/') );
$request->match( 'orderentry/contract' );
is(