-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Bug in simple YAML references #10888
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'm trying to debug this myself, but can anyone else confirm the bug? |
I've figured out the problem. However, in the 2.5 branch (note that I discovered t
8000
his problem in 2.4.4), I see this
I'm surprised. My interpretation of this makes me think that keys should be unique. Following the link provided by the docblock, the page states:
Thus, perhaps I didn't find a bug. Because I'm redefining keys. I think it would be better though if the parser issued a warning/error, rather than output the wrong thing. I have a use case for this in my project. I effectively concatenate YAML files. I start with a base YAML file and override keys in subsequent files as needed, which allows for a default configuration and overrides at a more localized level. Thus, key overrides should be allowed, and I'm asking for a spec change to YAML, not a bug fix. I will address this in my own fork of this repo. I'll provide a link here after I've done that. |
It's 3 lines of code, not including the version/tag changes. See tylercollier@31d3ca7. |
Please ignore this post, as it's incorrect. See following post. The above link is for my fork of symfony/symfony. If you want the fork of just the yaml component, see https://github.com/tylercollier/Yaml/tree/2.4.4-override-keys. You can use my fork via composer with the following:
|
Please ignore my
It looks like I can't do all this because phpunit itself directly depends on symfony/yaml. If I figure out how to switch it out for mine, I will update here. |
Ok, for now you can use this Note the
|
@tylercollier duplicate keys should be ignored according to yaml spec. this has been fixed in #10902 since 2.5. your described behavior in < 2.5 is still strange and buggy. |
To respond, I'll reiterate what I wrote above. I realize what I'm really asking for is a spec change to YAML. I think my use case of building YAML documents dynamically by concatenating them at run-time is a good example of why this would be helpful. Using the merge syntax is not possible if you're not sure if anchors have previously been defined. The spec says that if duplicate keys exist, they may be ignored but an appropriate warning should be issued. That doesn't currently happen, and I think it should. I'm glad it's been fixed in 2.5+, but for anyone who has < 2.5, now you have a way to deal with it with my pull request, if you want my behavior of allowing it. If you wanted to disallow it, you can take a look at the pull request to find out where you'd add code to deal with it. |
Closing as it's not relevant in 2.5+ and for 2.3/2.4 it does not matter that much as it's invalid YAML to use the same key (and behavior can be interpreted as undefined). |
I think I've found a bug with YAML reference parsing. Referencing multiple times results in grabbing data below the referenced section. I'm using the Symfony YAML component from version 2.4.4 with PHP 5.4.23 on Ubuntu 12.04.
Given
myfile.yaml
:Code:
Expected output:
Actual output:
Note how
[x] => y
has been replaced with[a] => b
.Note that you get the same actual output even if you remove the line
x: y
.The text was updated successfully, but these errors were encountered: