Skip to content

[Yaml] Fix parsing of block scalars in arrays #51444

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

Closed
wants to merge 2 commits into from

Conversation

NickSdot
Copy link
Contributor

@NickSdot NickSdot commented Aug 21, 2023

Q A
Branch? 5.4/6.3 for bug fixes
Bug fix? yes
New feature? no
Deprecations? no
License MIT

Valid Yaml

anyOf:
  - $ref: >-
      #/string/bar
nested:
  anyOf:
    - $ref: >-
        #/string/bar

Failing Test diff

 Array &0 (
     'anyOf' => Array &1 (
         0 => Array &2 (
-            '$ref' => ''
+            '$ref' => '#/string/bar'
         )
     )
     'nested' => Array &5 (
         'anyOf' => Array &6 (
             0 => Array &7 (
-                '$ref' => ''
+                '$ref' => '#/string/bar'
             )
         )
     )
 )

Notes

Similar cases that use block scalar folding are correctly handled by the parser. However, if the block scalar folding is in arrays the returned value is an empty string.

An example YAML file which is resulting in a broken parse is the Stripe OpenApi spec which can be found here. There are exactly 100 broken values when parsed.

I didn't consider this as a BC break since I assume that an empty string as a return value is in no ones interest. Feel free to let me know if you think otherwise and want me to target another branch.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "5.4" but it seems your PR description refers to branch "6.3 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

NickSdot added a commit to NickSdot/cebe-php-openapi that referenced this pull request Aug 22, 2023
…lds in reference objects. This is, according to the OpenApi spec, not legal. The lack of throwing an exception in situations like this lead to extra loops and a notable performance hit when working with larger specs like Stripe.
@NickSdot
Copy link
Contributor Author

NickSdot commented Sep 9, 2023

@mtarld, I don't mean to rush you, but I am allowing myself to ping you in case you missed the notification.

Lmk if there is something you would like to see changed in order to get this merged. Thank you.

@mtarld
Copy link
Contributor

mtarld commented Sep 12, 2023

Hey @NickSdot!
Everything LGTM, but I am not able to merge PRs on Symfony repository, therefore we must wait for a merger to merge it if everything is ok for her/him 🙂

@NickSdot
Copy link
Contributor Author

Sorry for my stupidity, I meant to tag @xabbuh, who is shown as the pending reviewer - not you. 🤦‍♂️ Thanks for jumping in anyway, @mtarld!

@xabbuh
Copy link
Member

xabbuh commented Nov 1, 2023

Thank you very much for working on this @NickSdot and sorry for the late review. I wondered why we actually needed two separate conditions and found out that there was also a little bug in isNextLineIndented(). After fixing that we can also simplify your patch a bit more. I have opened #52408 with these changes. But don't worry I have kept your commit so you will still get the credit for the bugfix.

@xabbuh xabbuh closed this Nov 1, 2023
@NickSdot
Copy link
Contributor Author

NickSdot commented Nov 2, 2023

Thank you very much for working on this @NickSdot and sorry for the late review. I wondered why we actually needed two separate conditions and found out that there was also a little bug in isNextLineIndented(). After fixing that we can also simplify your patch a bit more. I have opened #52408 with these changes. But don't worry I have kept your commit so you will still get the credit for the bugfix.

Thank you for taking this on @xabbuh. Yes, you spotted what I didn't fully understand. ;-)

However, glad a fix got merged!

@NickSdot NickSdot deleted the yaml-block-scalars-array branch November 4, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants