-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[YAML] Fixed parsing problem with nested DateTime lists #19029
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
@@ -398,7 +398,7 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references = | |||
$value = self::parseScalar($sequence, $flags, array(',', ']'), array('"', "'"), $i, true, $references); | |||
|
|||
// the value can be an array if a reference has been resolved to an array var | |||
if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) { | |||
if (!is_array($value) && !$value instanceof \DateTimeInterface && !$isQuoted && false !== strpos($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.
What about using !is_object()
here instead? That would also cover the case when an unserialized object was returned before.
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.
That might also do the job, of course, but I don't really overlook the consequences. Running strpos
on an object will most likely fail in most of the situations, so it's probably reasonable, yes. But as I said, I don't overlook every aspect — are there any kinds of serializable objects allowed? — so I wanted to keep it as specific as possible. Feel free to loosen this in case is_object()
doesn't break anything I don't see ...
Can you please add a test for this to avoid regressions? Status: Needs work |
Thank you @jkphl. |
…kphl, xabbuh) This PR was merged into the 3.1 branch. Discussion ---------- [YAML] Fixed parsing problem with nested DateTime lists | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19029 | License | MIT | Doc PR | The new handling for `DateTimeInterface` instances was introduced in Symfony 3.1. Commits ------- 0f47712 parse embedded mappings only if value is a string 4f13a76 [YAML] Fixed parsing problem with nested DateTime lists
Without this fix, DateTime-aware parsing of a YAML source containing nested lists of dates result in an error. Consider this:
Everything is fine, result is:
But making the
anniversary
a list of dateswill result in:
(I didn't capture the error messages with the most recent master branch, so line numbers differ somewhat)