Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Yaml Parser] Fix edge cases when parsing multiple documents#38228
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
1055435 to280797cComparexabbuh commentedSep 18, 2020
Thank you@digilist. That's indeed a good catch. 👍 Doesn't this also apply to the |
Uh oh!
There was an error while loading.Please reload this page.
280797c toa02c0a9Comparedigilist commentedSep 18, 2020
@xabbuh yes, makes sense, I adjusted the changes for 3.4 and rebased to 3.4 |
a02c0a9 to012ee4fComparefabpot commentedSep 18, 2020
Thank you@digilist. |
| $expected = ['a' => ['b' =>"row\nrow2\n"],'c' =>'d']; | ||
| // The parser was not used before, so there is a new line after row2 | ||
| $this->assertSame($expected,$this->parser->parse($longDocument)); |
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.
this doesn't look needed to me
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.
I just added this to show that this is the actual result. But yes, it can be removed.
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.
I understand though I think that's rather confusing when reading the test and trying to understand what is going on IMO.
| // The parser was not used before, so there is a new line after row2 | ||
| $this->assertSame($expected,$this->parser->parse($longDocument)); | ||
| $parser =newParser(); |
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.
as far as I can see we can simply use$this->parser when parsing the two documents
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.
see#38235
This PR was merged into the 3.4 branch.Discussion----------[Yaml] simplify the test| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | no| New feature? | no| Deprecations? | no| Tickets |#38228 (comment)| License | MIT| Doc PR |Commits-------bb64fc9 [Yaml] simplify the test
I identified some edge cases when parsing multiple YAML documents with the same parser instance, because the totalNumberOfLines was not reset and so any subsequent parsing considered the number of lines of the first document.
Consider this document:
Normally,
a.bwould be parsed asrow\nrow2\n. But if the parser parsed a shorter document before, the\nafter row2 was missing, as the parser considered it as the end of the file (that's why thec: dat the end is important).So this fix resets the
totalNumberOfLinesin the YAML parser tonullso that any subsequent parsing will initialize the value for the new document and does not use the file length of the first parsed document.I stumbled upon this because of a flickering unit test that was using the translation component. Sometimes the translated string contained a trailing
\nand sometimes not. In the end it was based on this bug, as the translation files were not loaded in the same order every time (not really sure why. It's somehow related to the cache state, but even with a warm cache it was not totally deterministic).