Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged

Conversation

@digilist
Copy link
Contributor

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

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:

a: b:|        row        row2c:d

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 thetotalNumberOfLines 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).

@xabbuh
Copy link
Member

Thank you@digilist. That's indeed a good catch. 👍 Doesn't this also apply to the3.4 branch?

@digilistdigilistforce-pushed theyaml-parser-new-line-edge-case branch from280797c toa02c0a9CompareSeptember 18, 2020 09:18
@digilistdigilist changed the base branch from4.4 to3.4September 18, 2020 09:18
@digilist
Copy link
ContributorAuthor

@xabbuh yes, makes sense, I adjusted the changes for 3.4 and rebased to 3.4

@digilistdigilistforce-pushed theyaml-parser-new-line-edge-case branch froma02c0a9 to012ee4fCompareSeptember 18, 2020 09:21
@fabpot
Copy link
Member

Thank you@digilist.

@fabpotfabpot merged commit2eeb75d intosymfony:3.4Sep 18, 2020
$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));
Copy link
Member

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

Copy link
ContributorAuthor

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.

xabbuh reacted with thumbs up emoji
Copy link
Member

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();
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@xabbuhxabbuh mentioned this pull requestSep 18, 2020
xabbuh added a commit that referenced this pull requestSep 18, 2020
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
This was referencedSep 27, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@xabbuhxabbuhxabbuh left review comments

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

5 participants

@digilist@xabbuh@fabpot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp