Skip Menu |

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

Report information
The Basics
Id: 15675
Status: resolved
Worked: -10 min
Priority: 0/
Queue: Data-JavaScript

People
Owner: Nobody in particular
Requestors: kevinj [...] activestate.com
Cc:
AdminCc:

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



Subject: Regexp causes perl to evaluate any number with a leading zero as an octal number
When trying to pass strings with leading zeros to javascript, the regular expression "/^-?(\d+\.?\d*|\.\d+)([eE]-?\d+)?$/" matches and causes perl to eval the string. In the case of "003", the perl eval dies and the javascript code produced is something like "var myvar = ;" which causes javascript to die. I've submitted a patch that fixes the regexp so that it doesn't match invalid numbers.
--- 207225 2005-11-10 08:45:19.000000000 -0800 +++ 207325 2005-11-10 08:45:55.000000000 -0800 @@ -1,4 +1,4 @@ -//depot/main/Appliance/mainline-unstable/src/pmx/cpan-packages/Data-JavaScript/JavaScript.pm#1 - branch change 204917 (text) +//depot/main/Appliance/mainline-unstable/src/pmx/cpan-packages/Data-JavaScript/JavaScript.pm#4 - edit change 207325 (text) package Data::JavaScript; use strict; @@ -55,7 +55,7 @@ if(! defined($elem) ){ return "$sym = @{[defined($undef) ? $undef : $UNDEF]};"; } - elsif ($elem =~ /^-?(\d+\.?\d*|\.\d+)([eE]-?\d+)?$/) { + elsif ($elem =~ /^-?((([1-9]+\d*)|0)(\.\d*)?|\.\d+)([eE]-?\d+)?$/) { return "$sym = " . eval($elem) . ";"; } return "$sym = '" . quotemeta($elem) . "';";
[guest - Thu Nov 10 11:52:30 2005]: Show quoted text
> > When trying to pass strings with leading zeros to javascript, the > regular expression "/^-?(\d+\.?\d*|\.\d+)([eE]-?\d+)?$/" matches > and causes perl to eval the string. In the case of "003", the perl > eval dies and the javascript code produced is something like "var > myvar = ;" which causes javascript to die. > > I've submitted a patch that fixes the regexp so that it doesn't match > invalid numbers.
This is actually a previously reported bug. I also have a pre-existing fix which you might wish to vet, available at http://web.mit.edu/belg4mit/Public/DJS1_10.tgz ...I had been waiting to do a major release.