From: Brian Cassidy Date: Wed, 8 Nov 2006 15:13:03 +0000 (+0000) Subject: fix undef values in params sent to uri_with() and uri_for() X-Git-Tag: 5.7099_04~282 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=d0f0fcf6ec9f6445e3e241b3edcd3920886a02cf;hp=69eecfe56af710d0698539ea25dc1bc84282e013 fix undef values in params sent to uri_with() and uri_for() --- diff --git a/Changes b/Changes index d4ea759..977ace6 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Catalyst. 5.7006 - Updated HTTP::Body dependency to 0.6, 0.5 can break on large POST requests. + - Skip utf8 fix for undef values in uri_with() and uri_for() 5.7005 2006-11-07 19:37:35 - Fixed lighttpd tests to be properly skipped. diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 06343ac..5edff66 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -925,6 +925,7 @@ sub uri_for { ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} ); for my $value ( values %$params ) { + next unless defined $value; for ( ref $value eq 'ARRAY' ? @$value : $value ) { $_ = "$_"; utf8::encode( $_ ); diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index dca909c..7624db7 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -516,6 +516,7 @@ sub uri_with { carp( 'No arguments passed to uri_with()' ) unless $args; for my $value ( values %$args ) { + next unless defined $value; for ( ref $value eq 'ARRAY' ? @$value : $value ) { $_ = "$_"; utf8::encode( $_ ); diff --git a/t/lib/TestApp/Controller/Engine/Request/URI.pm b/t/lib/TestApp/Controller/Engine/Request/URI.pm index 100557e..03cf758 100644 --- a/t/lib/TestApp/Controller/Engine/Request/URI.pm +++ b/t/lib/TestApp/Controller/Engine/Request/URI.pm @@ -63,4 +63,18 @@ sub uri_with_utf8 : Local { $c->forward('TestApp::View::Dump::Request'); } +sub uri_with_undef : Local { + my ( $self, $c ) = @_; + + my $warnings = 0; + local $SIG{__WARN__} = sub { $warnings++ }; + + # change the current uri + my $uri = $c->req->uri_with( { foo => undef } ); + + $c->res->header( 'X-Catalyst-warnings' => $warnings ); + + $c->forward('TestApp::View::Dump::Request'); +} + 1; diff --git a/t/live_engine_request_uri.t b/t/live_engine_request_uri.t index 5027b9c..943b276 100644 --- a/t/live_engine_request_uri.t +++ b/t/live_engine_request_uri.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 41; +use Test::More tests => 44; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -97,3 +97,10 @@ my $creq; ok( $response->is_success, 'Response Successful 2xx' ); like( $response->header( 'X-Catalyst-uri-with' ), qr/%E2%98%A0$/, 'uri_with ok' ); } + +# test with undef -- no warnings should be thrown +{ + ok( my $response = request("http://localhost/engine/request/uri/uri_with_undef"), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->header( 'X-Catalyst-warnings' ), 0, 'no warnings emitted' ); +} diff --git a/t/unit_core_uri_for.t b/t/unit_core_uri_for.t index dfeb95f..72ccda1 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 => 10; +use Test::More tests => 11; use URI; use_ok('Catalyst'); @@ -74,3 +74,12 @@ is( 'http://127.0.0.1/bar/baz', 'URI with no base or match' ); } +# test with undef -- no warnings should be thrown +{ + my $warnings = 0; + local $SIG{__WARN__} = sub { $warnings++ }; + + Catalyst::uri_for( $context, '/bar/baz', { foo => undef } )->as_string, + is( $warnings, 0, "no warnings emitted" ); +} +