Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RT#71452: Correct handling of dateTime parameters.

Existing code in lib/RPC/XML/Procedure.pm did not properly handle parameters
of the dateTime.iso8601 type. Also, there were no tests for these.
  • Loading branch information...
commit b1680acfcbdb1b991001888e6e5fd64f28341135 1 parent 427bddc
@rjray authored
Showing with 68 additions and 19 deletions.
  1. +21 −17 lib/RPC/XML/Procedure.pm
  2. +47 −2 t/30_method.t
View
38 lib/RPC/XML/Procedure.pm
@@ -71,7 +71,7 @@ $VERSION = eval $VERSION; ## no critic (ProhibitStringyEval)
# we use "datetime_iso8601" instead of "dateTime.iso8601", because that is how
# it has to be in the signature.
%VALID_TYPES = map { $_ => 1 }
- (qw(int i4 i8 double string boolean datetime_iso8601 nil array struct
+ (qw(int i4 i8 double string boolean dateTime.iso8601 nil array struct
base64));
###############################################################################
@@ -224,7 +224,7 @@ sub make_sig_table
return "$me: Unknown return type '$return'";
}
# Not going to add List::MoreUtils to my dependencies list, so suppress
- # this ciritic flag:
+ # this critic flag:
## no critic (ProhibitBooleanGrep)
if (grep { ! $VALID_TYPES{$_} } @rest)
{
@@ -666,6 +666,10 @@ sub call
"[$signature]"
);
}
+ elsif ($resptype eq 'dateTime.iso8601')
+ {
+ $resptype = 'datetime_iso8601';
+ }
# Set these in case the server object is part of the param list
local $srv->{signature} = ## no critic (ProhibitLocalVars)
@@ -882,7 +886,7 @@ when methods were implemented simply as hash references.
If there is more than one argument in the list, then the list is assumed to be
a sort of "ersatz" hash construct, in that one of the keys (C<signature>) is
-allowed to "stack" if it occur multiple times. Otherwise, any keys that occur
+allowed to "stack" if it occurs multiple times. Otherwise, any keys that occur
multiple times overwrite the previous value:
=over 12
@@ -1087,20 +1091,20 @@ other packages than this one, or useful in other contexts than this one.
The lightweight DTD for the layout can be summarized as:
- <!ELEMENT proceduredef (name, namespace?, version?, hidden?,
- signature+, help?, code)>
- <!ELEMENT methoddef (name, namespace?, version?, hidden?,
- signature+, help?, code)>
- <!ELEMENT functiondef (name, namespace?, version?, hidden?,
- signature+, help?, code)>
- <!ELEMENT name (#PCDATA)>
- <!ELEMENT namespace (#PCDATA)>
- <!ELEMENT version (#PCDATA)>
- <!ELEMENT hidden EMPTY>
- <!ELEMENT signature (#PCDATA)>
- <!ELEMENT help (#PCDATA)>
- <!ELEMENT code (#PCDATA)>
- <!ATTLIST code language (#PCDATA)>
+ <!ELEMENT proceduredef (name, namespace?, version?, hidden?,
+ signature+, help?, code)>
+ <!ELEMENT methoddef (name, namespace?, version?, hidden?,
+ signature+, help?, code)>
+ <!ELEMENT functiondef (name, namespace?, version?, hidden?,
+ signature+, help?, code)>
+ <!ELEMENT name (#PCDATA)>
+ <!ELEMENT namespace (#PCDATA)>
+ <!ELEMENT version (#PCDATA)>
+ <!ELEMENT hidden EMPTY>
+ <!ELEMENT signature (#PCDATA)>
+ <!ELEMENT help (#PCDATA)>
+ <!ELEMENT code (#PCDATA)>
+ <!ATTLIST code language (#PCDATA)>
The containing tag is always one of C<< <methoddef> >>, C<< <proceduredef> >>
or C<< <functiondef> >>. The tags that specify name, signatures and the code
View
49 t/30_method.t
@@ -9,10 +9,10 @@ use vars qw($obj $obj2 $flag $dir $vol $tmp $tmpfile $fh);
use File::Spec;
use Test::More;
-use RPC::XML qw($ALLOW_NIL RPC_INT);
+use RPC::XML qw($ALLOW_NIL RPC_INT RPC_DATETIME_ISO8601 time2iso8601);
use RPC::XML::Procedure;
-plan tests => 81;
+plan tests => 87;
($vol, $dir, undef) = File::Spec->splitpath(File::Spec->rel2abs($0));
$dir = File::Spec->catpath($vol, $dir, '');
@@ -427,6 +427,51 @@ END
like($val, qr/Error loading/, 'Correct error from reload() after unlink');
}
+# Per RT#71452, I learned that I never tested dateTime.iso8601 in any of the
+# signatures/calls, and that as of release 0.76, I may have bugs...
+
+undef $obj;
+$obj = RPC::XML::Procedure->new(
+ name => 'test.iso8601',
+ signature => 'string dateTime.iso8601',
+ code => sub {
+ my $date = shift;
+ return substr($date, 0, 4);
+ },
+);
+isa_ok($obj, 'RPC::XML::Procedure', '$obj');
+SKIP: {
+ skip 'Cannot test without object', 2
+ unless (ref($obj) eq 'RPC::XML::Procedure');
+
+ is($obj->match_signature('dateTime.iso8601'), 'string',
+ 'Test match_signature() with a dateTime.iso8601 input');
+ my $time = time2iso8601;
+ my $year = substr $time, 0, 4;
+ is($obj->call({}, RPC_DATETIME_ISO8601 $time)->value, $year,
+ 'Test a call with a dateTime.iso8601 argument');
+}
+
+$obj = RPC::XML::Procedure->new(
+ name => 'test.iso8601',
+ signature => 'dateTime.iso8601 int',
+ code => sub {
+ my $time = shift;
+ return time2iso8601($time);
+ },
+);
+isa_ok($obj, 'RPC::XML::Procedure', '$obj');
+SKIP: {
+ skip 'Cannot test without object', 2
+ unless (ref($obj) eq 'RPC::XML::Procedure');
+
+ is($obj->match_signature('int'), 'dateTime.iso8601',
+ 'Test match_signature() with a dateTime.iso8601 output');
+ my $time = time;
+ is($obj->call({}, RPC_INT $time)->value, time2iso8601($time),
+ 'Test a call with a dateTime.iso8601 return value');
+}
+
END
{
# Just in case...
Please sign in to comment.
Something went wrong with that request. Please try again.