Skip to content

Symfony YAML parser doesn't handle complex YAML format #20579

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

Closed
BourotBenjamin opened this issue Nov 21, 2016 · 10 comments
Closed

Symfony YAML parser doesn't handle complex YAML format #20579

BourotBenjamin opened this issue Nov 21, 2016 · 10 comments

Comments

@BourotBenjamin
Copy link

As described here :
http://yaml.org/spec/1.2/spec.html#id2760395

A question mark and space (“? ”) indicate a complex mapping key.

But, when I try to load a valid YAML file using complex mappig, I got an error :

Error parsing YAML, invalid file "diet.fr.yml"

ParseException: Unable to parse at line 3 (near "? "1"").

My file content :

---
diet:
  ? "1"
  :
    name: végétalien

As PECL YAML extension ( https://pecl.php.net/package/yaml ) exists, works fine and seems more complete than symfony's one, wouldn't be more simple to replace Symfony's YAML component by php extension ?

What do you think ?

@stof
Copy link
Member

stof commented Nov 21, 2016

We cannot replace the Symfony component by the PHP extension, as it would force people to install an uncommon PHP extension to use Symfony, which is a no-go (even the much more common mbstring can be an issue for some people, so my answer is not a wild guess).

And as the Symfony parser is turning mappings to associative PHP arrays, it cannot support using arrays as keys for instance. This is why support for complex mappings was never implemented until now.
We know that the parser does not implement the full spec (we even document this fact). We implement the most common features in config files (which is our focus for the component), and add more features based on feature requests, contributions, and the complexity it adds.
Btw, AFAIK you are the first one requesting it ever while the Symfony parser exists since years.

@xabbuh
Copy link
Member

xabbuh commented Nov 22, 2016

What should be possible is to detect the case of complex mappings and provide a more meaningful exception messages.

@flip111
Copy link
Contributor

flip111 commented Nov 28, 2016

@BourotBenjamin possibly it should be possible to make a wrapper around the pecl extension which implements the interface needed by symfony. Then you could replace the yaml class yourself.

@BourotBenjamin
Copy link
Author

As my problem was created by an external service ( OneSky ) that exports complex yml event when you don't need complex keys, and I used a bundle to import and export files ( OpenClassrooms/OneSkyBundle ), I thought the best idea was to handle the problem in this bundle.

So I made a pull request to asks to install pecl_yaml with this bundle and made it laod the file by the pelc_yaml loader but export it with the SF2's yaml dumper.

@javiereguiluz
Copy link
Member

@xabbuh do you think these improved exception messages would be easy to implement? Will you be able to do that for 3.3 (the feature freeze is in 32 days)? Thanks!

@xabbuh
Copy link
Member

xabbuh commented Feb 27, 2017

@javiereguiluz I am not sure, but I try to find a way to make that change.

@xabbuh
Copy link
Member

xabbuh commented Mar 19, 2017

see #22058

@xabbuh
Copy link
Member

xabbuh commented Mar 19, 2017

I think we need to deprecate the current behaviour first (see #22059).

fabpot added a commit that referenced this issue Mar 20, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

[Yaml] deprecate "? " starting unquoted strings

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #20579
| License       | MIT
| Doc PR        |

Commits
-------

731a74e [Yaml] deprecate "? " starting unquoted strings
@fabpot fabpot closed this as completed Mar 20, 2017
@xabbuh
Copy link
Member

xabbuh commented May 21, 2017

The deprecated behaviour will be removed in #22770.

@ghost
Copy link

ghost commented Jun 4, 2020

@BourotBenjamin I found the parsing Yaml file using PHP instead of c-extension badly inefficient.
Could you found a wrapper (class extension) over Symfony yam that uses the c-extension?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants