Permalink
Browse files

Guard against non-named args in GET calls

  • Loading branch information...
1 parent cf89ad8 commit 85acaabc9b28e988fd07f02227da56ae4a8bebe4 @claesjac committed Dec 7, 2011
Showing with 13 additions and 2 deletions.
  1. +3 −1 lib/JSON/RPC/Simple/Client.pm
  2. +10 −1 t/03-client.t
View
4 lib/JSON/RPC/Simple/Client.pm
@@ -80,7 +80,9 @@ sub AUTOLOAD {
);
}
else {
-
+ die "GET only supports named parameters" if $params && ref $params ne 'HASH';
+ $params = {} unless $params;
+
my $params = join "&", map { "$_=" . URI::Escape::uri_escape_utf8($params->{$_}) } keys %$params;
my $request_uri = $self->{uri} . $method . '?' . ${params};
View
11 t/03-client.t
@@ -3,7 +3,8 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::Exception;
+use Test::More tests => 5;
use JSON::RPC::Simple;
@@ -18,3 +19,11 @@ is($r, "Hello World");
my $client2 = JSON::RPC::Simple->connect(SERVER_ADDR, { GET => 1 });
$r = $client2->add({ a => 32, b => 10 });
is($r, 42);
+
+throws_ok {
+ $client2->foo([]);
+} qr/GET only supports named parameters/;
+
+lives_ok {
+ $client2->now();
+};

0 comments on commit 85acaab

Please sign in to comment.