8000 Unable to parse ruby generated yaml with unknown mappings · Issue #8562 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Unable to parse ruby generated yaml with unknown mappings #8562

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
fh opened this issue Jul 24, 2013 · 11 comments
Closed

Unable to parse ruby generated yaml with unknown mappings #8562

fh opened this issue Jul 24, 2013 · 11 comments
Labels

Comments

@fh
Copy link
fh commented Jul 24, 2013

I am generating a Yaml config file with rubys YAML::dump, and want to read the generated file with Symfonys Yaml-Component. However, YAML::dump adds some unwanted "object mapping" to some hashes, which causes the Symfony Parser to fail:

--- 
something: !map:Mash
  foo: bar

The !map:Mash causes the parsing to fail. Technically, this is probably no bug, this the designated object type Yaml is supposed to map the data to is unknown - but maybe it is a good idea to either mention this issue in the documentation, or provide some possibility to ignore/override it.

Right now, my workaround is a pretty ugly one, I am removing it on the ruby side in the resulting yaml string: https://github.com/till/easybib-cookbooks/blob/bibcd/bibcd/providers/app.rb#L12 - and I would love to do it somewhat cleaner and error prone.

Any thoughts here?

@fabpot
Copy link
Member
fabpot commented Jul 24, 2013

Indeed, the YAML component does not implement the whole specification, but only a subset that is widely used for configuration files. YAML files like you mentioned are not parsed correctly by the current parser and there are no plans to implement this syntax.

@lsmith77
Copy link
Contributor

i guess we are missing support for http://www.yaml.org/spec/1.1/#tag%20shorthand/ (note this also exists in 1.2 but isn't listed as nicely in the spec so I am linking 1.1)?

@lsmith77
Copy link
Contributor

@fabpot but would you accept a patch that would implement this? (note I do not have time to work on this .. but someone else might ..)

@fabpot
Copy link
Member
fabpot commented Jul 24, 2013

If someone can implement this without a big refactoring of the current code, and without adding a ton of code, I'm fine with it.

@webdevilopers
Copy link

👍

@webdevilopers
Copy link

In my example I had the following YAML structure:

--- 
- - :custom_field_str_1
  - Bemerkung 2
- - :custom_field_str_2
  - Neues Feld
- - :custom_field_num_1
  - Paletten
- - :custom_field_num_2
  - Bemerkung 3

This is the way Rails resp. Active Record serializes it:
http://rubyjunky.com/rails-activerecord-serialize.html

The Symfony YAML 8000 component will fail:
Unable to parse at line 3 (near " - Bemerkung 2")

@coderofsalvatio suggested me to take a look at the PHP YAML Extension:
http://php.net/manual/en/book.yaml.php

Indeed this will correctely parse my YAML (coming from an entity column named $customFields):

$parsed = yaml_parse($customFields);
var_dump($parsed);

array (size=4)
  0 => 
    array (size=2)
      0 => string ':custom_field_str_1' (length=19)
      1 => string 'Bemerkung 2' (length=11)
  1 => 
    array (size=2)
      0 => string ':custom_field_str_2' (length=19)
      1 => string 'Neues Feld' (length=10)
  2 => 
    array (size=2)
      0 => string ':custom_field_num_1' (length=19)
      1 => string 'Paletten' (length=8)
  3 => 
    array (size=2)
      0 => string ':custom_field_num_2' (length=19)
      1 => string 'Bemerkung 3' (length=11)

Maybe this will help some other users like @bjoerne2 at the moment:
#11019

Is this interesting for the refactoring too @lsmith77 @fabpot ?

@webdevilopers
Copy link

Does anybody know if Symfony 2.6 YAML object-maps will solve my use case issue above @nicolas-grekas ?

@stof
Copy link
Member
stof commented Nov 7, 2014

no it won't. It is not related to the supported YAML features. As you can see in the PR you linked, it does not change the parsing itself, but only the way maps are returned after being parsed (and your example does not even use a map, but lists)

@webdevilopers
Copy link

Thanks for the info @stof . I'm not that familiar with YAML yet.

Maybe @lsmith77 is still interested in this improvement?

@lsmith77
Copy link
Contributor

covering the core spec of YAML should be a goal, covering as many of the optional features as possible is a nice to have.

@fabpot
Copy link
Member
fabpot commented Oct 5, 2015

Closing as we will never support the whole spec and it seems that few people have this issue.

@fabpot fabpot closed this as completed Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
0