-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Using a PHP class constant for a key in a YAML hash as a method argument produces a ParseException #36624
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
Comments
Thank you for the example. This helped to reproduce it. It looks like the parser still doesn't handle constants well in all places. For example, this doesn't work: App\Example:
calls:
- method: addOptions
arguments:
- !php/const App\Example::CONSTANT_1: 'value_0'
key_1: "value_1"
key_2: "value_2" while this parses correctly: App\Example:
calls:
- method: addOptions
arguments:
- key_1: "value_1"
!php/const App\Example::CONSTANT_1: 'value_0'
key_2: "value_2" |
Absolutely, I wasn't really sure what was wrong so I just tried to give the detail that I had at least. Oh neat!! I didn't realize that that syntax existed for invoking methods, that's so much better! And thanks for the explanation, I reproduced it and have a much clearer understanding of what is wrong now. Thanks a ton for tracking this down @xabbuh, really appreciated. |
Thank you for providing this very good example that allows to reproduce it. I don't know how hard it will be to fully fix this, but now I at least have some test input for the parser. 😃 |
…block (jnye) This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [Yaml] Fix for #36624; Allow PHP constant as first key in block | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #36624 | License | MIT | Doc PR | When using a PHP constant in the first key of a mapping the parser would throw an exception. However if you used a PHP constant in any other key but the first it was allowed. This fix allows PHP constant as the first key. I've included a test for this parser error along with the fix. Commits ------- 46f635c [Yaml] Fix for #36624; Allow PHP constant as first key in block
* 3.4: [Yaml] Fix for #36624; Allow PHP constant as first key in block Use PHPUnit 9.3 on php 8. fix mapping errors from unmapped forms [Validator] Add target guards for Composite nested constraints
* 4.4: [Validator] RangeTest: fix expected deprecation [Yaml] Fix for #36624; Allow PHP constant as first key in block Use PHPUnit 9.3 on php 8. fix mapping errors from unmapped forms [Validator] Add target guards for Composite nested constraints
* 5.1: [Validator] RangeTest: fix expected deprecation Fix bad merge [Yaml] Fix for #36624; Allow PHP constant as first key in block Use PHPUnit 9.3 on php 8. fix mapping errors from unmapped forms [Validator] Add target guards for Composite nested constraints
Symfony version(s) affected: 4.4.7
Description
Virtually the same as #35179 but with different exceptions.
When trying to use a PHP class constant as a YAML key for a hash (as a method argument), I receive one of the following.
\Symfony\Component\Yaml\Exception\ParseException
with the messageThe constant "\VENDOR\PRODUCT\Example" is not defined at line 7 (near "!php/const \VENDOR\PRODUCT\Example").
if I use YAML Variant A below.\Symfony\Component\Yaml\Exception\ParseException
with the messageMalformed inline YAML string: ""\VENDOR\PRODUCT\Example" at line 7 (near ""\VENDOR\PRODUCT\Example").
if I use YAML Variant B below. I observe the same behavior when using single quotes.How to reproduce
Using the following class and Symfony YAML DI files produces the above.
Also, the control case and global PHP constants (in both variants) work as expected, i.e:
The text was updated successfully, but these errors were encountered: