-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Disallow object usage inside Route #27727
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
[Routing] Disallow object usage inside Route #27727
Conversation
faaa501
to
59f5f54
Compare
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.
For 4.1 as bug fix? the issue also exists on 2.8, but there we don't have an "export" method as we rely only on var_export()
.
@@ -746,6 +746,10 @@ public static function export($value): string | |||
return 'null'; | |||
} | |||
if (!\is_array($value)) { | |||
if (\is_object($value)) { |
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.
if (\is_object($value) && !method_exists($value, '__set_state')) {
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.
even objects with __set_state
are broken, as the logic currently replaces new lines by a concatenation with "\n"
instead (because when var_export-ing a scalar, new lines appear only inside strings).
If we want to keep support for objects with __set_state
, it should be handled as a separate case (and I would put it before the if (!is_array())
case then, rather than nesting in 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.
even objects with __set_state are broken
indeed, then let's keep it unsupported :)
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 purpose of this PR is to disallow object usage, and avoid to export objects (via var_export
). Thus, the fact that __set_state
exists or not is not relevant. The dumped file does not work when we export an object (because of \n
replacements).
Did not see the comments above :)
@@ -746,6 +746,10 @@ public static function export($value): string | |||
return 'null'; | |||
} | |||
if (!\is_array($value)) { | |||
if (\is_object($value)) { | |||
throw new \InvalidArgumentException('Symfony\Component\Routing\Route cannot contain objects'); |
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.
missing dot at end of message
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.
Fixed and squashed.
59f5f54
to
f1b3ffc
Compare
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.
(for 4.1)
…Bonfante) This PR was submitted for the master branch but it was squashed and merged into the 4.1 branch instead (closes symfony#27754). Discussion ---------- [HttpFoundation] missing namespace for RedisProxy I think the intention was to check if is instance of \Symfony\Component\Cache\Traits\RedisProxy | Q | A | ------------- | --- | Branch? | 4.1 (becareful when merging) | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 8e0acfc [HttpFoundation] missing namespace for RedisProxy
…regex (nicolas-grekas) This PR was merged into the 4.1 branch. Discussion ---------- [Routing] fix too much greediness in host-matching regex | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#27721 | License | MIT | Doc PR | - Commits ------- e16b302 [Routing] fix too much greediness in host-matching regex
f1b3ffc
to
426fb45
Compare
Thank you @paxal. |
This PR was submitted for the master branch but it was merged into the 4.1 branch instead (closes #27727). Discussion ---------- [Routing] Disallow object usage inside Route | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | ? | Fixed tickets | #27723 | License | MIT | Doc PR | ✘ As discussed in #27723 the `Route` object should not support nested objects as attributes (`requirements`, `defaults`, ...). Thus, if detected, an `\InvalidArgumentException` will be thrown. Will fix #27723 Commits ------- 426fb45 [Routing] Disallow object usage inside Route
As discussed in #27723 the
Route
object should not support nested objects as attributes (requirements
,defaults
, ...).Thus, if detected, an
\InvalidArgumentException
will be thrown.Will fix #27723