-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Yaml::parse() fails at double quoted multi line messages #11109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't understand exactly what you mean when you talk about the different Symfony versions. Are 2.2.0 and 2.4.6 affected too, or is it only affecting 2.5.0 ? |
I read it as 2.2.0 and 2.4.6 are affected and the line is still included in 2.5.0 Actually the commit is 3ab9a6e, so if this line causes the error, it is included in 2.1.0 up to today. |
apfelbox is right: the line of code I'm pointing at is included from 2.1.0 up to 2.5.0. But I have only tested it in 2.2.0 and 2.4.6 - both versions are definitely affected. |
Using symfony/yaml 2.7.0, it looks like any multiline "flow" scalars fail. Double-quoted definitely fails, but so do plain, and single-quoted. $ php -r '
require "vendor/autoload.php";
var_dump(\Symfony\Component\Yaml\Yaml::parse(<<<EOM
---
a: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum justo,
rhoncus non libero eget.
EOM
));
'
PHP Fatal error: Uncaught exception 'Symfony\Component\Yaml\Exception\ParseException'
with message 'Unable to parse at line 3 (near " rhoncus non libero eget.").' in
/Users/john/dev/symfony-yaml-test/vendor/symfony/yaml/Parser.php:285 This is pretty common is yaml land, and really hurts interop with other yaml libs. I've been running into this left and right trying to use symfony/yaml to load yaml files that were generate with ruby stdlib yaml (psych). |
Just want to add a couple of additional notes here.
The resulting file looks like this (though the details don't matter so much - just the line wrapping):
It's also equally possible to use my ruby example here as a test string - the reference parser is happy with it, symfony is not. This kind of string wrapping seems like a commonly used core feature of YAML, but possibly isn't encountered so often in configuration files where string tend to be short. |
Please check out #19304 which should solve this issue. |
This PR was submitted for the 2.7 branch but it was merged into the 3.2-dev branch instead (closes #19304). Discussion ---------- [Yaml] fix parsing multi-line mapping values | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11109 | License | MIT | Doc PR | Commits ------- 3954530 [Yaml] fix parsing multi-line mapping values
The YAML specification has the following example for a multi line message in double quotes:
Write that in a MultilineDoubleQuotedMessage.yml and try to Yaml::parse('MultilineDoubleQuotedMessage.yml') - Symfony will throw an exception like this:
I tried that in Symfony 2.2.0 and 2.4.6, but the underlying issue seems to be the reg exp in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Inline.php#L246 , which lives on in Symfony 2.5.0.
A unit test in Symfony\Component\Yaml\Tests\YamlTest could look something like this:
The text was updated successfully, but these errors were encountered: