TiMESPLiNTER
TiMESPLiNTER

Reputation: 5889

Ending Newline Behavior of YAML::parse() with Scalar content written in block form using a literal style

I have the following YAML file:

street:    |
           123 Tornado Alley
           Suite 16
price:     1.47

So if I parse that file with YAML::parse() from the symfony2 YAML component I expect that I get an array with:

string "123 Tornado Alley
Suite 16"

in it. But instead of that I get:

array (
  'street' => '123 Tornado Alley
Suite 16
'
// ...
)

So a determining line break after Suite 16.

Is there any reason why the parser behaves like that? To me it looks like a bug...

Upvotes: 0

Views: 799

Answers (1)

hakre
hakre

Reputation: 197832

This \n at the end is not a bug, it must be there.

This is conforming with YAML 1.1 block scalar literal style.

http://yaml.org/spec/1.1/#|%20literal%20style/

See also Example 2.13. In literals, newlines are preserved.

You might just want to rtrim the data before you continue.

Upvotes: 3

Related Questions