Development

#2916 (Bug in Spyc : losing data with successive load/dump)

You must first sign up to be able to contribute.

Ticket #2916 (new defect)

Opened 8 months ago

Bug in Spyc : losing data with successive load/dump

Reported by: Eric.Lemoine Assigned to: fabien
Priority: major Milestone:
Component: configuration Version: 1.0.11
Keywords: spyc dump Cc:
Qualification: Unreviewed

Description

Hello

There is a bug in Spyc code inside the dump method. Indeed the following code does not work as expected :

$spyc = new Spyc();

$load = $spyc->load("key: '07'");
var_dump($load);

$dump = $spyc->dump($load);
var_dump($dump);

$load = $spyc->load($dump);
var_dump($load);

The result is :

array(1) {
  ["key"]=>
  string(2) "07"
}
string(12) "---
key: 07
"
array(1) {
  ["key"]=>
  int(7)
}

So first we had '07' as the value (a string) and after a dump we now have 7 (an integer). The problem is that the dump method does not quote the value.

In Spyc.class.php we see in _dumpNode method :

      // It's mapped
      $string = $spaces.$key.': '.$value."\n";

The value is not quoted.

syck has the same dumping bug. However with syck, the second load read the value as octal since the value begins with 0. But that is not the problem :)

Thank you in advance

Eric