Skip Menu |
 

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

Report information
The Basics
Id: 16491
Status: open
Priority: 0/
Queue: Data-JavaScript-Anon

People
Owner: Nobody in particular
Requestors: alexmv [...] bestpractical.com
Cc:
AdminCc:

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

Attachments


Subject: Use single quotes for strings
Download (untitled) / with headers
text/plain 355b
Data::JavaScript::Anon uses double quotes for constructing strings. This makes it very hard to embed into onclick attributes and the like. Luckily, double quotes and single quotes do the exact same thing in javascript. As I see no advantage to using double quotes, I've attached is a patch which switches to using single quotes when strings are needed.
Only in Data-JavaScript-Anon-singlequote/: Makefile Only in Data-JavaScript-Anon-singlequote/: blib diff -ru Data-JavaScript-Anon-0.6/lib/Data/JavaScript/Anon.pm Data-JavaScript-Anon-singlequote/lib/Data/JavaScript/Anon.pm --- Data-JavaScript-Anon-0.6/lib/Data/JavaScript/Anon.pm 2005-07-26 04:48:34.000000000 -0400 +++ Data-JavaScript-Anon-singlequote/lib/Data/JavaScript/Anon.pm 2005-12-14 16:49:45.000000000 -0500 @@ -170,7 +170,7 @@ return $value if $value =~ /$RE_NUMERIC/; # Escape and quote - '"' . _escape($value) . '"'; + "'" . _escape($value) . "'"; } # Turn a single perl value into a javascript hash key @@ -186,7 +186,7 @@ return $value if $value =~ /$RE_NUMERIC_HASHKEY/; # Escape and quote - '"' . _escape($value) . '"'; + "'" . _escape($value) . "'"; } # Create a Javascript array given the javascript array name @@ -222,7 +222,7 @@ sub _escape { my $text = shift; - $text =~ s/(\"|\\)/\\$1/g; # Escape quotes and backslashes + $text =~ s/(\'|\\)/\\$1/g; # Escape quotes and backslashes $text =~ s/\n/\\n/g; # Escape newlines in a readable way $text =~ s/\r/\\r/g; # Escape CRs in a readable way $text =~ s/\t/\\t/g; # Escape tabs in a readable way Only in Data-JavaScript-Anon-singlequote/: pm_to_blib diff -ru Data-JavaScript-Anon-0.6/t/02_results.t Data-JavaScript-Anon-singlequote/t/02_results.t --- Data-JavaScript-Anon-0.6/t/02_results.t 2005-07-26 04:48:34.000000000 -0400 +++ Data-JavaScript-Anon-singlequote/t/02_results.t 2005-12-14 16:55:35.000000000 -0500 @@ -32,16 +32,16 @@ 3com 2131.231fd2132 +0x21x }; -my @keywords = qw{ - abstract boolean break byte case catch char class const continue - debugger default delete do double else enum export extends false final - finally float for function goto if implements import in instanceof int - interface long native new null package private protected public return - short static super switch synchronized this throw throws transient true - try typeof var void volatile while with -}; - -plan tests => (@numbers + @not_numbers + @keywords + 5); +my @keywords = qw{ + abstract boolean break byte case catch char class const continue + debugger default delete do double else enum export extends false final + finally float for function goto if implements import in instanceof int + interface long native new null package private protected public return + short static super switch synchronized this throw throws transient true + try typeof var void volatile while with +}; + +plan tests => (@numbers + @not_numbers + @keywords + 6); foreach ( @numbers ) { ok( Data::JavaScript::Anon->is_a_number( $_ ), "$_ is a number" ); @@ -50,34 +50,38 @@ ok( ! Data::JavaScript::Anon->is_a_number( $_ ), "$_ is not a number" ); } -# Test that keywords come out quoted -foreach ( @keywords ) { - is( Data::JavaScript::Anon->anon_hash_key($_), '"' . $_ . '"', - "anon_hash_key correctly quotes keyword $_ used as hash key" ); +# Test that keywords come out quoted +foreach ( @keywords ) { + is( Data::JavaScript::Anon->anon_hash_key($_), '"' . $_ . '"', + "anon_hash_key correctly quotes keyword $_ used as hash key" ); } # Do a simple test of most of the code in a single go my $rv = Data::JavaScript::Anon->anon_dump( [ 'a', 1, { a => { a => 1, } }, \"foo" ] ); -is( $rv, '[ "a", 1, { a: { a: 1 } }, "foo" ]', +is( $rv, q|[ 'a', 1, { a: { a: 1 } }, 'foo' ]|, 'Generates expected output for simple combination struct' ); # Test for CPAN bug #7183 -is( Data::JavaScript::Anon->anon_hash_key( "0596000278" ), '"0596000278"', +is( Data::JavaScript::Anon->anon_hash_key( "0596000278" ), q|'0596000278'|, 'anon_hash_key correctly escapes 0-leading non-octal' ); # Test for CPAN bug #11882 (forward slash not being escaped) -is( Data::JavaScript::Anon->anon_scalar( 'C:\\devel' ), '"C:\\\\devel"', +is( Data::JavaScript::Anon->anon_scalar( 'C:\\devel' ), q|'C:\\\\devel'|, 'anon_scalar correctly escapes forward slashes' ); -# Also make sure double quotes are escaped -is( Data::JavaScript::Anon->anon_scalar( 'foo"bar' ), '"foo\\"bar"', - 'anon_scalar correctly escapes double quotes' ); +# Make sure double quotes are not escaped +is( Data::JavaScript::Anon->anon_scalar( 'foo"bar' ), q|'foo"bar'|, + "anon_scalar correctly doesn't escape double quotes" ); + +# Also make sure single quotes are escaped +is( Data::JavaScript::Anon->anon_scalar( "foo'bar" ), q|'foo\\'bar'|, + 'anon_scalar correctly escapes single quotes' ); # Test for generalised case of CPAN bug # (newline not being escaped) -$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'); +$rv = Data::JavaScript::Anon->anon_dump( [ "a\nb", "a\rb", "a b", "a'b", "a\bb" ] ); +is( $rv, q|[ 'a\nb', 'a\rb', 'a\tb', 'a\\'b', 'a\010b' ]|, 'escape tabs, newlines, CRs and control chars'); 1;
Date: Thu, 15 Dec 2005 16:21:27 +1100
From: Adam Kennedy <adam [...] phase-n.com>
To: bug-Data-JavaScript-Anon [...] rt.cpan.org
Subject: Re: [cpan #16491] Use single quotes for strings
RT-Send-Cc:
Download (untitled) / with headers
text/plain 957b
Internet explorer does not treat single quotes the same as double quotes. The general rule is to use double quotes as often as possible. That said, I'm not entirely sure what the specifics of this problem is as I only have it second hand from the JSAN project people. Until someone can clear up what the issue is for me, I won't be applying this patch. Adam K Guest via RT wrote: Show quoted text
> This message about Data-JavaScript-Anon was sent to you by guest <> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=16491 > > > Data::JavaScript::Anon uses double quotes for constructing strings. This makes it very hard to embed into onclick attributes and the like. Luckily, double quotes and single quotes do the exact same thing in javascript. As I see no advantage to using double quotes, I've attached is a patch which switches to using single quotes when strings are needed.
From: David Dorward <david [...] dorward.me.uk>
Download (untitled) / with headers
text/plain 310b
On Wed Dec 14 17:06:17 2005, guest wrote: Show quoted text
> Data::JavaScript::Anon uses double quotes for constructing strings. > This makes it very hard to embed into onclick attributes and the > like.
The return value can be pushed through HTML::Entities, or you can quote your attribute values with single quotes.


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.