Skip Menu |

This queue is for tickets about the Data-JavaScript-Anon CPAN distribution.

Report information
The Basics
Id: 19915
Status: resolved
Priority: 0/
Queue: Data-JavaScript-Anon

People
Owner: Nobody in particular
Requestors: cpan [...] aaroncrane.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bugs with '0' as anon_hash_key and "0\n" as number; patch+test included
Data::JavaScript::Anon->anon_hash_key incorrectly returns undef for string '0', causing an uninitialized-value warning, and a syntax error in the generated JavaScript. Data::JavaScript::Anon->is_a_number incorrectly returns true for strings containing a number followed by a newline character. I've attached a patch with failing tests, and fixes for both bugs. -- Aaron Crane
Subject: dja.diff
diff -urN Data-JavaScript-Anon-0.9.orig/lib/Data/JavaScript/Anon.pm Data-JavaScript-Anon-0.9/lib/Data/JavaScript/Anon.pm --- Data-JavaScript-Anon-0.9.orig/lib/Data/JavaScript/Anon.pm 2006-06-04 03:48:02.000000000 +0100 +++ Data-JavaScript-Anon-0.9/lib/Data/JavaScript/Anon.pm 2006-06-15 11:44:45.000000000 +0100 @@ -25,10 +25,10 @@ # The final combination of all posibilities for a straight number # The string to match must have no extra characters - $RE_NUMERIC = qr/^(?:\+|\-)??(?:$real|$_hex|$_oct)$/; + $RE_NUMERIC = qr/^(?:\+|\-)??(?:$real|$_hex|$_oct)\z/; # The numeric for of the hash key is similar, but without the + or - allowed - $RE_NUMERIC_HASHKEY = qr/^(?:$real|$_hex|$_oct)$/; + $RE_NUMERIC_HASHKEY = qr/^(?:$real|$_hex|$_oct)\z/; %KEYWORD = map { $_ => 1 } qw{ abstract boolean break byte case catch char class const @@ -177,7 +177,7 @@ # Turn a single perl value into a javascript hash key sub anon_hash_key { my $class = shift; - my $value = _STRING($_[0]) ? shift : return undef; + my $value = _STRING($_[0]) || $_[0] eq '0' ? shift : return undef; # Quote if it's a keyword return '"' . $value . '"' if $KEYWORD{$value}; diff -urN Data-JavaScript-Anon-0.9.orig/t/02_results.t Data-JavaScript-Anon-0.9/t/02_results.t --- Data-JavaScript-Anon-0.9.orig/t/02_results.t 2006-06-04 03:48:02.000000000 +0100 +++ Data-JavaScript-Anon-0.9/t/02_results.t 2006-06-15 11:39:56.000000000 +0100 @@ -32,10 +32,10 @@ 0x2131 0xaaad32 -0x21312 +0x212 +0X212 01 02 03 04 05 01251 002123 00000 }; -my @not_numbers = qw{ +my @not_numbers = ("0\n", qw{ a 09 +09 -09 ++1 +-34 3com 2131.231fd2132 +0x21x -}; +}); my @keywords = qw{ abstract boolean break byte case catch char class const continue @@ -46,7 +46,7 @@ try typeof var void volatile while with }; -plan tests => (@numbers + @not_numbers + @keywords + 5); +plan tests => (@numbers + @not_numbers + @keywords + 6); foreach ( @numbers ) { ok( Data::JavaScript::Anon->is_a_number( $_ ), "$_ is a number" ); @@ -84,5 +84,9 @@ $rv = Data::JavaScript::Anon->anon_dump( [ "a\nb", "a\rb", "a b", "a\"b", "a\bb" ] ); is( $rv, '[ "a\nb", "a\rb", "a\tb", "a\\"b", "a\010b" ]', 'escape tabs, newlines, CRs and control chars'); +# Test that hash keys which are numeric zero don't turn into empty string +$rv = Data::JavaScript::Anon->anon_dump( { 0 => 'zero' } ); +is( $rv, '{ 0: "zero" }', q[numeric-zero hash keys don't disappear]); + 1;
I don't have time to look at this, but if you like I can add you to the SVN repository that the module is in, and you can patch and prepare the next release directly. Then when you are done, I can quickly review and trigger the auto-release script. Good enough?
Subject: Re: [rt.cpan.org #19915] Bugs with '0' as anon_hash_key and "0\n" as number; patch+test included
Date: Sat, 17 Jun 2006 23:14:50 +0100
To: via RT <bug-Data-JavaScript-Anon [...] rt.cpan.org>
From: Aaron Crane <arc [...] cpan.org>
ADAMK via RT writes: Show quoted text
> if you like I can add you to the SVN repository that the module is in, and > you can patch and prepare the next release directly.
Sure, that would be fine. -- Aaron Crane
Subject: Re: [rt.cpan.org #19915] Bugs with '0' as anon_hash_key and "0\n" as number; patch+test included
Date: Sun, 18 Jun 2006 15:47:05 +0100
To: ADAMK via RT <bug-Data-JavaScript-Anon [...] rt.cpan.org>
From: Aaron Crane <arc [...] cpan.org>
ADAMK via RT writes: Show quoted text
> if you like I can add you to the SVN repository that the module is in, and > you can patch and prepare the next release directly.
I've fixed those bugs in your SVN, plus a couple of others I found while I was looking at the code. All the fixes have tests. I don't plan to make any more changes. Thanks. -- Aaron Crane