-
Notifications
You must be signed in to change notification settings - Fork 326
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
colon can be in a plain scalar #28
Conversation
👍 This exact issue is preventing us from adopting libyaml, we have lots of documents with urls in them. I see this was discussed in #21, any ETA for merging? Thanks! |
@dbeer1 are you saying you have lots of docs like:
or
libyaml is perfectly fine with the former. I haven't seen much of the latter (urls in flow collections) in the wild. |
Yeah, we have a lot of lines like this (in basically all our files because most of them were created from a template):
We are currently using yaml-cpp to parse, which can correctly read this document. Looking to switch to libyaml as it has been significantly faster in our tests and works on all of our platforms, but it chokes on documents like that. |
I've read the various discussions on this:
It seems like this scanner error was introduced as a placeholder while the syntax of mappings was being discussed. Is this reason still valid? This error is somewhat problematic as other YAML parser and emitter implementations follow the spec and will create documents that cannot interoperate with libyaml. Searching the internet, I've seen many complaints about this behavior and talk of people patching it locally. |
Reviewing the spec, it seems to be clear that a space must follow the colon, if the colon is to be considered a mapping separator. I completely concur with that logic. Therefore I think we can move forward with this. But... I now have a working test suite and libyaml test harness here: https://github.com/ingydotnet/yaml-dev-kit/ One edge case is this: |
I agree that Compare https://github.com/yaml/pyyaml/blob/master/lib/yaml/scanner.py#L1301 vs https://github.com/yaml/libyaml/blob/master/src/scanner.c#L3438 |
@dbeer, right, these should all become valid:
I'll add tests for them to the suite. BTW, I just moved the test suite to |
Here's an existing test that is affected by this: https://github.com/yaml/yaml-test-suite/blob/master/test/4ABK.tml As you can see it is marked to be skipped by libyaml testing. |
I think you probably meant to address @dbeer1 |
I restored the empty value behavior in pyyaml in yaml/pyyaml#45. I guess we should do the same here with libyaml? Now it processes your test as follows:
The case with omitted keys seems to be significantly more complicated as the grammers in the parser need to be reworked. |
The pyyaml pull request has been merged and I think the logic here should be updated to match. That is, a ':' should terminate a scalar in the flow context if it is followed not just by a space but also by ',[]{}'. For example: |
Thanks @dbeer1. I'll add a test to the YAML Test Suite for this. |
any plans to merge this? |
I added a test for a plain url in a flow mapping: yaml/yaml-test-suite@1eacbab I also updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead and merge @perlpunk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me.
There's one thing that should be noted, though.
Now it is parsed valid, but the result is wrong, as the colon becomes part of the content:
Given that this is the wrong behaviour (as mentioned previously in this thread), the question is, does it make sense to add this fix, making something become valid, but wrong? |
I also wanted to add a script for testing error cases (#81) before merging this, however, @ingydotnet requested changes for which I don't have time now, so this has to go without the additional tests. |
So it seems we are not sure what the correct behaviour is. |
I think that I think we can shore this up in 1.3, and that applying this patch is correct for now. I'd like to hold off on applying this until we hear from @flyx. |
I couldn't find tests for those edge cases in yaml-test-suite. @perlpunk: where does that gist come from? I couldn't find it anywhere in the test suite. |
@jstoiko yeah, these cases are not yet in the test suite because we still have to figure out the correct results :-/ |
Allowing this basically makes libyaml implement neither 1.1 nor 1.2 (since there are more 1.2 changes it is not aware of). However, it takes its liberties anyway. I have no strong opinion about whether it is a good idea to allow it. |
If this is accepted is makes other parsers inconsistent. |
This is a followup to yaml#28 See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following productions. This commit will allow `[http://example]`, but still fail for: - `[:foo]` - `[foo:]`
I created PR #104 |
This is a followup to yaml#28 See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following productions. This commit will allow `[http://example]`, but still fail for: - `[:foo]` - `[foo:]`
@asomov and, btw, YAML parsers are already pretty inconsistent: http://matrix.yaml.io/ ;-) |
FYI, go-yaml has already addressed the issue: go-yaml/yaml#295 |
@perlpunk : the page you show is inconsistent, not the parsers. Why they try to test 1.2 spec against the parsers which explicitly do not support it ! |
@jstoiko : why do you propose this change to all the parsers WITHOUT proposal for the corner cases ? |
That's not true. PyYAML accepts
Well, sure, they should be tested against 1.1 test cases. But none of us has time to write a test suite for 1.1. We already have enough to do with 1.2. I could try to make it more clear on the matrix page which parsers implement 1.1/1.0. What do you think, would that help? Maybe create an issue for the https://github.com/perlpunk/yaml-test-matrix, and then we can discuss it there, since it's probably off topic here. |
@perlpunk : PyYAML 3.12 does exactly what it should - rejects to accept inconsistent colon `
` |
@asomov ok, I can confirm that when testing that locally. The PyYAML in https://github.com/yaml/yaml-editor, however, accepts it. That's because the PyYAML in yaml-editor uses PyYAML master branch and this already has the fix from yaml/pyyaml#45.
Only that production number 154/155 seem to have a mistake, allowing also
http://yaml.org/spec/1.1/#id907281 "9.1.3. Plain" |
@perlpunk (as I already said many times)
|
I would say that it makes perfect sense to allow However, |
We are working on YAML 1.3: https://github.com/yaml/summit.yaml.io/wiki/YAML-RFC-Index
I'm implementing a Processor in Perl for 1.2, and I'm trying to design it in a way that it can also support 1.3 in the future. I'm contributing to yaml-test-suite and yaml-editor, and I created yaml-test-matrix to avoid a mess in the future. |
to make it clear: I'd vote for closing this and instead use #104 |
This is a followup to #28 See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following productions. This commit will allow `[http://example]`, but still fail for: - `[:foo]` - `[foo:]`
This is a followup to yaml#28 See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following productions. This commit will allow `[http://example]`, but still fail for: - `[:foo]` - `[foo:]`
This is a followup to #28 See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following productions. This commit will allow `[http://example]`, but still fail for: - `[:foo]` - `[foo:]` See https://gist.github.com/perlpunk/de2c631a7b0e9002de351a680eadb573 for all the relevant cases where this change applies.
#104 was merged |
No description provided.