data-dump icon indicating copy to clipboard operation
data-dump copied to clipboard

Data::Dump::dump silently changes string to integer

Open godsarmy opened this issue 8 years ago • 6 comments

Hi

I am using Data::Dump v1.23 and found issue that Data::Dump::dump sliently changes string to integer to cause YAML dump print incorrect result.

Here are the example code

use YAML::XS;
use Data::Dump;

my $data = { id => [ '0123', '0234']};

print "before dump\n";
print YAML::XS::Dump($data);

Data::Dump::dump($data);

print "after dump\n";
print YAML::XS::Dump($data);

And if i launch the script, you can find the second YAML::XS::Dump print element in $data as integer.

$ perl testy.pl
before dump

---
id:
- '0123'
- '0234'
{ id => ["0123", "0234"] }
after dump

---
id:
- 0123
- 0234

godsarmy avatar Aug 27 '16 07:08 godsarmy

Isn't this a bug in YAML::XS::Dump then?

gisle avatar Sep 08 '16 20:09 gisle

It is not. because YAML::XS::Dump gives right answer before calling Data::Dump::dump

godsarmy avatar Oct 18 '16 06:10 godsarmy

I'm a big fan of this module! But I do have to second this issue, as it's not just with YAML, it appears Data::Dump coerces the variables to numeric, silencing any following warnings, and causing them to behave a bit like a dualvar:

$ perl -wMstrict
use Data::Dump;
use Devel::Peek;
my $y = "4x";
dd $y;
print $y+3, " ", $y.3, "\n";
Dump($y);
__END__
"4x"
7 4x3
SV = PVNV(0x964262) at 0x984424
  REFCNT = 1
  FLAGS = (POK,IsCOW,pIOK,pNOK,pPOK)
  IV = 4
  NV = 4
  PV = 0x993912 "4x"\0
  CUR = 2
  LEN = 10
  COW_REFCNT = 1

haukex avatar Jul 03 '17 12:07 haukex

It appears this is the same as RT#86592. Update: I see that Pull Requests #7 and #11 provide possible patches.

haukex avatar Jul 03 '17 12:07 haukex

Using Data::Dump with data structures later send to MongoDB also has some rather strange effects; e.g. strings like "Information" being stored as numeric Inf. See https://jira.mongodb.org/browse/PERL-992 for more information.

heikojansen avatar Aug 27 '18 14:08 heikojansen

This also causes issues with JSON::Validator.

gam3 avatar Jul 02 '20 06:07 gam3