Skip Menu |
 

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

Report information
The Basics
Id: 39859
Status: new
Priority: 0/
Queue: Data-JavaScript-Anon

People
Owner: Nobody in particular
Requestors: allter [...] gmail.com
Cc:
AdminCc:

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



Subject: String keys of hash which represent big integers are not quoted in anon_dump
Download (untitled) / with headers
text/plain 873b
Perl preserves contents of big integer values in scalars when you don't do math operations on them. In JavaScript there are no scalars: there are numeric and string objects. D::JS::A does not quote hash keys of structures so javascript machines store their values as numbers. Their contents is then subject to change if their values overcome the possibilities of numeric stashes of a particular JS machine. A temporary workaround for D::JS::A user would be: - Switch to any of JSON implementations - Change the logic of their javascript part by including string symbol to hash key and then accessing it in their javascript by "hash[ 'x' + integer_key ]". Permanent workaround for D::JS::A would be quoting all keys of js objects as suggested in bug 7183: http://rt.cpan.org/Public/Bug/Display.html?id=7183. Attached is a test script which could be used in a patch.
Subject: string_key.t
Download string_key.t
text/x-perl 357b
#!/usr/bin/perl use strict; our $hashref; BEGIN { $hashref = { '18810807140010000110' => 'value', }; } use Test::Simple tests => scalar keys %$hashref; use Data::JavaScript::Anon; my $js = Data::JavaScript::Anon->anon_dump( $hashref ); ok $js =~ /['"]$_["']/, "$_ is quoted in dump string" for keys %$hashref; #use Data::Dumper; warn '$js '.Dumper $js;
From: allter [...] gmail.com
Download (untitled) / with headers
text/plain 641b
Втр. Окт. 07 08:06:17 2008, allter писал: Show quoted text
> D::JS::A does not quote hash keys of structures so javascript machines > store their values as numbers. Their contents is then subject to change > if their values overcome the possibilities of numeric stashes of a > particular JS machine.
I forgot to check that it is also applicable to arbitrary values. I.e. for array values and object(hash) field values. When D::JS::A sees it looks like number it encodes it as a number, but on javascript side there is a loss of precision. The complete workaround would be to inspect a kind of perl structure value's stash and quote accordingly.


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.