Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Data/MessagePack/PP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ sub _pack {
if ( $flags & B::SVp_POK ) { # raw / check needs before double

if ( $self->{prefer_integer} ) {
if ( $value =~ /^-?[0-9]+$/ ) { # ok?
if ( $value =~ /^(0|-?[1-9][0-9]*)$/ ) { # ok?
# checks whether $value is in (u)int32
my $ivalue = 0 + $value;
if (!(
Expand Down
2 changes: 2 additions & 0 deletions t/05_preferred_int.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ my @dat = (
'', 'c4 00',
'0', '00',
'1', '01',
'01', 'c4 02 30 31',
'10', '0a',
'-1', 'ff',
'-0', 'c4 02 2d 30',
'-10', 'f6',
'-', 'c4 01 2d',
''.0xEFFF => 'cd ef ff',
Expand Down
2 changes: 2 additions & 0 deletions xs-src/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ STATIC_INLINE int try_int(enc_t* enc, const char *p, size_t len) {
if (len > 10) { return 0; }
}

if (*p == '0' && len != 1) { return 0; }

#if '9'=='8'+1 && '8'=='7'+1 && '7'=='6'+1 && '6'=='5'+1 && '5'=='4'+1 \
&& '4'=='3'+1 && '3'=='2'+1 && '2'=='1'+1 && '1'=='0'+1
do {
Expand Down