Symfony YAML parsing content with comma

Is there a bug in the Symfony Yaml component, or is this intended Yaml standard behavior? My understanding is that the comma in the script below should act like a normal content character.

\Symfony\Component\Yaml\Yaml::parse("test: 1,2");

      

Actual result:

array("test" => 12)

      

Expected Result:

array("test" => "1,2")

      

+3


source to share


1 answer


This is not a bug in Symfony - or at least this is expected Symfony behavior. You passed the unquoted value to the parser, which looks like a number, so it treats it as such and extracts non-numeric characters. The Symfony documentation talks about numeric literals in the Yaml component , although it refers to underscores. The Symfony Yaml Format documentation states:

Finally, there are other cases where strings must be quoted, whether you use single or double quotes:

  • When the string looks like a number, like integers (like 2, 14, etc.), floats (like 2.6, 14.9) and exponential numbers (like 12e7, etc.) (otherwise this will be considered a numeric value);

If you run the following code, you get the expected output:

Symfony\Component\Yaml\Yaml::parse('test: "1,2"');

      



Result:

["test" => "1,2"]

      

Note how the double quotes indicate a string value that should not be treated as a numeric literal.

+1


source







All Articles