Skip Menu |

This queue is for tickets about the PHP-Serialization CPAN distribution.

Report information
The Basics
Id: 48594
Status: resolved
Priority: 0/
Queue: PHP-Serialization

People
Owner: Nobody in particular
Requestors: ediap [...] users.sourceforge.net
johnpupu [...] gmail.com
Cc:
AdminCc:

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



Subject: int error ?
$key = '020'; $value = '001'; $a->{$key} = $value; print serialize( $a ); result is a:1:{i:20;i:1;} but it's not the result i want. i assign $key, and $value is a string; but it will convert to int after serialization... I check the source code..., line :380 if ( $val =~ /^-?\d{1,10}$/ && abs($val) < 2**31 ) { i modify to if ( $val =~ /^-?[1,9]{1,10}$/ && abs($val) < 2**31 ) { and it works. if my modification don't get some errors or warnings , could you modify it ? Thx ^^
From: modified
if ( $val =~ /^-?[1-9]\d{0,9}$/ && abs($val) < 2**31 ) { 在 2009-08-10 13:27:58 星期一 時,http://johnpupu.myopenid.com/ 寫到: Show quoted text
> $key = '020'; > $value = '001'; > > $a->{$key} = $value; > print serialize( $a ); > > > > result is > a:1:{i:20;i:1;} > > but it's not the result i want. > > i assign $key, and $value is a string; > > but it will convert to int after serialization... > > I check the source code..., > > > line :380 > if ( $val =~ /^-?\d{1,10}$/ && abs($val) < 2**31 ) { > > i modify to > if ( $val =~ /^-?[1,9]{1,10}$/ && abs($val) < 2**31 ) { > > and it works. > > > if my modification don't get some errors or warnings , could you
modify it ? Show quoted text
> > Thx ^^
From: ediap [...] users.sourceforge.net
[snip] Show quoted text
> if ( $val =~ /^-?[1-9]\d{0,9}$/ && abs($val) < 2**31 ) {
[snip] Show quoted text
> > if ( $val =~ /^-?[1,9]{1,10}$/ && abs($val) < 2**31 ) {
[snip] The above proposed solutions will not convert '0' string to an int 0, which might be not what one wants. Here is a slightly modified patch that takes this issue into account: --- Serialization.pm.orig 2010-03-09 22:43:16.932910000 +0100 +++ Serialization.pm 2010-03-09 22:45:18.426285000 +0100 @@ -377,7 +377,7 @@ return $self->_encode('obj', $val); } elsif ( ! ref($val) ) { - if ( $val =~ /^-?\d{1,10}$/ && abs($val) < 2**31 ) { + if ( $val =~ /^-?(?:0|[1-9]\d{0,9})$/ && abs($val) < 2**31 ) { return $self->_encode('int', $val); } elsif ( $val =~ /^-?\d+\.\d*$/ && !$iskey) { BR, /Adam
Fixed in PHP-Serialization-0.34.tar.gz