Author: cutting
Date: Wed Jun 11 19:40:47 2014
New Revision: 1601999
URL: http://svn.apache.org/r1601999
Log:
AVRO-1462. Perl: Stop serializer warnings about Non-ASCII decimal chars.
Contributed by John Karp.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/perl/lib/Avro/BinaryEncoder.pm
avro/trunk/lang/perl/t/02_bin_encode.t
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1601999&r1=1601998&r2=1601999&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Jun 11 19:40:47 2014
@@ -84,6 +84,9 @@ Trunk (not yet released)
AVRO-1513. Perl: Remove test plans from unit test files.
(John Karp via cutting)
+ AVRO-1462. Perl: Stop spurious serializer warnings about Non-ASCII
+ decimal characters. (John Karp via cutting)
+
Avro 1.7.6 (15 January 2014)
NEW FEATURES
Modified: avro/trunk/lang/perl/lib/Avro/BinaryEncoder.pm
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/perl/lib/Avro/BinaryEncoder.pm?rev=1601999&r1=1601998&r2=1601999&view=diff
==============================================================================
--- avro/trunk/lang/perl/lib/Avro/BinaryEncoder.pm (original)
+++ avro/trunk/lang/perl/lib/Avro/BinaryEncoder.pm Wed Jun 11 19:40:47 2014
@@ -22,6 +22,7 @@ use warnings;
use Config;
use Encode();
use Error::Simple;
+use Regexp::Common qw(number);
our $max64;
our $complement = ~0x7F;
@@ -89,7 +90,10 @@ sub encode_boolean {
sub encode_int {
my $class = shift;
my ($schema, $data, $cb) = @_;
- if ($data !~ /^-?\d+$/ || abs($data) > 0x7fffffff) {
+ if ($data !~ /^$RE{num}{int}$/) {
+ throw Avro::BinaryEncoder::Error("cannot convert '$data' to integer");
+ }
+ if (abs($data) > 0x7fffffff) {
throw Avro::BinaryEncoder::Error("int ($data) should be <= 32bits");
}
@@ -100,7 +104,10 @@ sub encode_int {
sub encode_long {
my $class = shift;
my ($schema, $data, $cb) = @_;
- if ($data !~ /^-?\d+$/ || abs($data) > $max64) {
+ if ($data !~ /^$RE{num}{int}$/) {
+ throw Avro::BinaryEncoder::Error("cannot convert '$data' to long
integer");
+ }
+ if (abs($data) > $max64) {
throw Avro::BinaryEncoder::Error("int ($data) should be <= 64bits");
}
my $enc = unsigned_varint(zigzag($data));
Modified: avro/trunk/lang/perl/t/02_bin_encode.t
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/perl/t/02_bin_encode.t?rev=1601999&r1=1601998&r2=1601999&view=diff
==============================================================================
--- avro/trunk/lang/perl/t/02_bin_encode.t (original)
+++ avro/trunk/lang/perl/t/02_bin_encode.t Wed Jun 11 19:40:47 2014
@@ -81,10 +81,17 @@ sub primitive_ok {
} "Avro::BinaryEncoder::Error", "65 bits";
for (qw(long int)) {
- dies_ok {
+ throws_ok {
primitive_ok $_ => "x", undef;
- } "numeric values only";
- }
+ } 'Avro::BinaryEncoder::Error', 'numeric values only';
+ };
+ # In Unicode, there are decimals that aren't 0-9.
+ # Make sure we handle non-ascii decimals cleanly.
+ for (qw(long int)) {
+ throws_ok {
+ primitive_ok $_ => "\N{U+0661}", undef;
+ } 'Avro::BinaryEncoder::Error', 'ascii decimals only';
+ };
}
## spec examples