-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml] parse PHP constants in mapping keys #22878
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
Q | A |
---|---|
Branch? | 3.3 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #22854 |
License | MIT |
Doc PR |
@@ -208,7 +208,7 @@ private function doParse($value, $flags) | |||
$this->refs[$isRef] = end($data); | |||
} | |||
} elseif ( | |||
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values) | |||
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values) |
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.
the !php/const
tag is a bit special as it is separated with a colon from its value instead of a space which is used when parsing other tags
@xabbuh with this the YAML will appear to be valid but, in addition to the |
Do you have a concrete example where this breaks a real application? This combination sounds like a real edge case to me. |
I mean that in 3.2, the following service: foo:
class: AppBundle\Foo
arguments:
-
!php/const:PHP_SAPI: bar would have the following injected as first argument: array(
'cli' => 'bar'
); in 3.3, even with this, it would inject: array(
' !php/const:PHP_SAPI' => 'bar'
); the DI file loader uses this edge combination since 3.3, so consts arent't resolved (the transition would be named |
After solving the other problem described in the issue, I did encounter the problem explained by @chalasr:
|
This is indeed an issue when the |
constants should now be evaluated in mapping keys @tgalopin Can you give this another try? Status: Needs Review |
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.
Works for me 👍
Works for me too, thanks @xabbuh ! |
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 opened #22913 to get rid of this fix in 4.0.
@@ -221,7 +221,14 @@ private function doParse($value, $flags) | |||
try { | |||
Inline::$parsedLineNumber = $this->getRealCurrentLineNb(); | |||
$i = 0; | |||
$key = Inline::parseScalar($values['key'], 0, null, $i, !(Yaml::PARSE_KEYS_AS_STRINGS & $flags)); | |||
$evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags); |
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 really don't get why we would ever want to use this flag, this is like saying "I don't want to respect the spec", don't you think we should just deprecate it?
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.
We need this to deprecate the previous behaviour. Otherwise we have no smooth upgrade path in 3.4.
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.
#21774 introduced a small bc break anyway and this only allows people to go back to the old behavior by using this flag, right?
Thank you @xabbuh. |
This PR was merged into the 3.3 branch. Discussion ---------- [Yaml] parse PHP constants in mapping keys | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22854 | License | MIT | Doc PR | Commits ------- ae52fe6 [Yaml] parse PHP constants in mapping keys
This PR was squashed before being merged into the 3.4 branch (closes #22913). Discussion ---------- [Yaml] Deprecate tags using colon | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Using a colon in a tag doesn't look like yaml and causes trouble (see #22878), so I propose to just deprecate these tags in favor of more consistent tags. ```yml - !php/const:PHP_INT_MAX - !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` would become ```yml - !php/const PHP_INT_MAX - !php/object O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` Commits ------- 9815af3 [Yaml] Deprecate tags using colon
This PR was squashed before being merged into the 3.4 branch (closes #22913). Discussion ---------- [Yaml] Deprecate tags using colon | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Using a colon in a tag doesn't look like yaml and causes trouble (see symfony/symfony#22878), so I propose to just deprecate these tags in favor of more consistent tags. ```yml - !php/const:PHP_INT_MAX - !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` would become ```yml - !php/const PHP_INT_MAX - !php/object O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` Commits ------- 9815af3 [Yaml] Deprecate tags using colon
This PR was squashed before being merged into the 3.4 branch (closes #22913). Discussion ---------- [Yaml] Deprecate tags using colon | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Using a colon in a tag doesn't look like yaml and causes trouble (see symfony/symfony#22878), so I propose to just deprecate these tags in favor of more consistent tags. ```yml - !php/const:PHP_INT_MAX - !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` would become ```yml - !php/const PHP_INT_MAX - !php/object O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` Commits ------- 9815af3 [Yaml] Deprecate tags using colon
This PR was squashed before being merged into the 3.4 branch (closes #22913). Discussion ---------- [Yaml] Deprecate tags using colon | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Using a colon in a tag doesn't look like yaml and causes trouble (see symfony/symfony#22878), so I propose to just deprecate these tags in favor of more consistent tags. ```yml - !php/const:PHP_INT_MAX - !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` would become ```yml - !php/const PHP_INT_MAX - !php/object O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` Commits ------- 9815af3 [Yaml] Deprecate tags using colon
This PR was squashed before being merged into the 3.4 branch (closes #22913). Discussion ---------- [Yaml] Deprecate tags using colon | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Using a colon in a tag doesn't look like yaml and causes trouble (see symfony/symfony#22878), so I propose to just deprecate these tags in favor of more consistent tags. ```yml - !php/const:PHP_INT_MAX - !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` would become ```yml - !php/const PHP_INT_MAX - !php/object O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";} ``` Commits ------- 9815af3 [Yaml] Deprecate tags using colon
This PR was merged into the 6.2 branch. Discussion ---------- [Yaml] Remove legacy parsing rule | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - As far as I understood correctly, this part of the regexp has been introduced in #22878 to support a syntax that has been deprecated in #22913 and removed in 4.0. Commits ------- 5d7f9f2 [Yaml] Remove legacy parsing rule