Skip to content

Parsing strings that look like numbers changed in release 0.87 #111

@veryrusty

Description

@veryrusty

The change to turn off the internal POK flag in release 0.87 has impacted how strings that look like numbers are parsed.

Using a variation of the code from #68:

use v5.16;
use YAML::XS qw/ Load /;
use Devel::Peek qw/ Dump /;
use Data::Dumper qw/ Dumper /;
my $yaml = "foo: 0003\nbar: 03.30";
my $data = Load $yaml;
say Dumper $data;
Dump $data->{foo};
Dump $data->{bar};

YAML::[email protected] gives strings

$VAR1 = {
          'bar' => '03.30',
          'foo' => '0003'
        };

SV = PVIV(0x5648b041dde0) at 0x5648b04145f8
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 3
  PV = 0x5648b0422f60 "0003"\0
  CUR = 4
  LEN = 10
SV = PVNV(0x5648b03fb300) at 0x5648b0414688
  REFCNT = 1
  FLAGS = (NOK,POK,pIOK,pNOK,pPOK)
  IV = 3
  NV = 3.3
  PV = 0x5648b05e4000 "03.30"\0
  CUR = 5
  LEN = 10

While YAML::[email protected] has munged them, numified 0003 and dropped the zeros from 03.30

$VAR1 = {
          'bar' => '3.3',
          'foo' => 3
        };

SV = PVNV(0x55b424e98300) at 0x55b424eb15f8
  REFCNT = 1
  FLAGS = (IOK,pIOK)
  IV = 3
  NV = 3
  PV = 0x55b424ec00a0 "0003"\0
  CUR = 4
  LEN = 10
SV = PVNV(0x55b424e98320) at 0x55b424eb1688
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  IV = 3
  NV = 3.3
  PV = 0x55b424fb2c10 "3.3"\0
  CUR = 3
  LEN = 32

With $YAML::XS::QuoteNumericStrings defaulting to true, I'd expect those leading zeros to be preserved (as the 0.86 release does).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions