-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1055435
to
280797c
Compare
Thank you @digilist. That's indeed a good catch. 👍 Doesn't this also apply to the |
280797c
to
a02c0a9
Compare
@xabbuh yes, makes sense, I adjusted the changes for 3.4 and rebased to 3.4 |
a02c0a9
to
012ee4f
Compare
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 = new Parser(); |
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.b
would be parsed asrow\nrow2\n
. But if the parser parsed a shorter document before, the\n
after row2 was missing, as the parser considered it as the end of the file (that's why thec: d
at the end is important).So this fix resets the
totalNumberOfLines
in the YAML parser tonull
so 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
\n
and 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).