Reputation: 2596
Is there a bug within Symfony Yaml component or is this the intended behavior from the Yaml standard? As per my understanding the comma in the scenario below should act a regular content character.
\Symfony\Component\Yaml\Yaml::parse("test: 1,2");
Actual result:
array("test" => 12)
Expected result:
array("test" => "1,2")
Upvotes: 3
Views: 491
Reputation: 8276
This isn't a bug within Symfony - or at least, it's Symfony expected behavior. You passed a non-quoted value to the parser that looks like a number, so it treats it as such and strips out the non-numeric charcaters. The Symfony documentation talks about numeric literals in its Yaml component, although that is in regards to underscores. The Symfony Yaml Format documentation explicitly states:
Finally, there are other cases when the strings must be quoted, no matter if you're using single or double quotes:
- When the string looks like a number, such as integers (e.g. 2, 14, etc.), floats (e.g. 2.6, 14.9) and exponential numbers (e.g. 12e7, etc.) (otherwise, it would be treated as a numeric value);
If you run the following code you will get your expected result:
Symfony\Component\Yaml\Yaml::parse('test: "1,2"');
Result:
["test" => "1,2"]
Notice how the double-quotes are indicating a string value that should not be treated as a numeric literal.
Upvotes: 1