Skip Menu |
 

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

Report information
The Basics
Id: 7183
Status: stalled
Worked: 45 min
Priority: 0/
Queue: Data-JavaScript-Anon

People
Owner: adamk [...] cpan.org
Requestors: dan [...] kreft.net
Cc:
AdminCc:

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



Subject: anon_hash_key() bug
Distribution: Data-JavaScript-Anon-0.2 anon_hash_key() has a very subtle bug in the way it handle quoting of hash keys. Given a hash of Amazon.com ASINS: my $asins = { '0596000278' => 'Programming Perl' }; While anon_hash_key() rightfully rejects this as a valid octal number, it fails to quote the key because it matches /^\w$/, so given the following code: use Data::JavaScript::Anon; print Data::JavaScript::Anon->var_dump('asins', $asins); ...Firefox 0.8 (Linux), Netscape 7.1 (Linux), and Netscape 4.78 (Linux) will all complain thusly: Warning: 09 is not a legal ECMA-262 octal constant And they're right for saying so. :-) The simplest and safest way to handle this is to quote *everything* except strings that are recognized as being numbers. As an aside, there really is no good reason that I can think of for *not* quoting all non-numeric strings...taking advantage of JS's automagical quoting for object key names is just syntactic sugar and doesn't really buy us anything except maybe a few less bytes to download.
Download anon.patch
text/x-diff 180b
173,174c173 < # Don't quote if it is just a set of word characters or numeric < return $value if $value =~ /^\w+$/; --- > # Don't quote if it is a numeric string


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.