Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
jkphl wants to merge2 commits intosymfony:masterfromjkphl:master
Closed

[YAML] Fixed parsing problem with nested DateTime lists#19029

jkphl wants to merge2 commits intosymfony:masterfromjkphl:master

Conversation

@jkphl
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

Without this fix, DateTime-aware parsing of a YAML source containing nested lists of dates result in an error. Consider this:

$data = ['date' => ['annivesary' =>new \DateTime('now')]];$yaml = Yaml::dump($data);var_dump($yaml);$parsed = Yaml::parse($yaml, Yaml::PARSE_DATETIME);print_r($parsed);

Everything is fine, result is:

string(48) "date:    annivesary: 2016-06-11T11:26:30+02:00"Array(    [date] => Array        (            [annivesary] => DateTime Object                (                    [date] => 2016-06-11 11:26:30.000000                    [timezone_type] => 1                    [timezone] => +02:00                )        ))

But making theanniversary a list of dates

$data = ['date' => ['annivesary' => [new \DateTime('now')]]];$yaml = Yaml::dump($data);var_dump($yaml);$parsed = Yaml::parse($yaml, Yaml::PARSE_DATETIME);print_r($parsed);

will result in:

string(50) "date:    annivesary: [2016-06-11T12:00:05+02:00]"PHP Warning:  strpos() expects parameter 1 to be string, object given in [...]\vendor\symfony\yaml\Inline.php on line 382PHP Catchable fatal error:  Object of class DateTime could not be converted to string in [...]\vendor\symfony\yaml\Inline.php on line 386

(I didn't capture the error messages with the most recent master branch, so line numbers differ somewhat)


// 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) && !$valueinstanceof \DateTimeInterface && !$isQuoted &&false !==strpos($value,':')) {
Copy link
Member

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.

Copy link
ContributorAuthor

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. Runningstrpos 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 caseis_object() doesn't break anything I don't see ...

@xabbuh
Copy link
Member

Can you please add a test for this to avoid regressions?

Status: Needs work

@fabpot
Copy link
Member

Thank you@jkphl.

jkphl reacted with thumbs up emoji

fabpot added a commit that referenced this pull requestJun 17, 2016
…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 string4f13a76 [YAML] Fixed parsing problem with nested DateTime lists
@fabpotfabpot mentioned this pull requestOct 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@jkphl@xabbuh@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp