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] 🐛 throw ParseException on invalid date#57968

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

Merged
xabbuh merged 1 commit intosymfony:5.4fromhomersimpsons:patch-1
Aug 12, 2024

Conversation

@homersimpsons
Copy link
Contributor

@homersimpsonshomersimpsons commentedAug 9, 2024
edited
Loading

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesNone
LicenseMIT

(found insymfony-tools/docs-builder#179)

When parsing the following yaml:

date: 6418-75-51

symfony/yaml will throw an exception:

$ php main.phpPHP Fatal error:  Uncaught Exception: Failed to parse time string (6418-75-51) at position 6 (5): Unexpected character in /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php:714Stack trace:#0 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(714): DateTimeImmutable->__construct()#1 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(312): Symfony\Component\Yaml\Inline::evaluateScalar()#2 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(80): Symfony\Component\Yaml\Inline::parseScalar()#3 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(790): Symfony\Component\Yaml\Inline::parse()#4 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(341): Symfony\Component\Yaml\Parser->parseValue()#5 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(86): Symfony\Component\Yaml\Parser->doParse()#6 /tmp/symfony-yaml/vendor/symfony/yaml/Yaml.php(77): Symfony\Component\Yaml\Parser->parse()#7 /tmp/symfony-yaml/main.php(8): Symfony\Component\Yaml\Yaml::parse()#8 {main}  thrown in /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php on line 714

This is because the "month" is invalid. Fixing the "month" will trigger about the same issue because the "day" would be invalid.

With the current change it will throw aParseException.

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.2" but it seems your PR description refers to branch "7.2 for features / 5.4, 6.4, and 7.1 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

Copy link
Member

@stofstof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This needs some tests to prevent regressions

@derrabus
Copy link
Member

What does the YAML spec say about invalid date strings? Is the fallback to a plain string the expected behavior?

@homersimpsons
Copy link
ContributorAuthor

homersimpsons commentedAug 9, 2024
edited
Loading

This needs some tests to prevent regressions

I added a test. I do not know how far should I go with the "invalid dates"

What does the YAML spec say about invalid date strings? Is the fallback to a plain string the expected behavior?

I cannot seem to find anything searchinghttps://yaml.org/spec/1.2.2/ for "date", "invalid", "incorrect".

I also searched for "date" inhttps://github.com/yaml/yaml-test-suite without success.

I tried withhttps://github.com/yaml/yaml-reference-parser/blob/main/parser-1.2/javascript (I had to hack a bit around to make it work) but it looks like this is not checking explicitly for dates:
image

@xabbuhxabbuh added the Yaml labelAug 11, 2024
@xabbuhxabbuh modified the milestones:7.2,5.4Aug 11, 2024
@carsonbotcarsonbot changed the title🐛 Gracefully handle invalid dates[Yaml] 🐛 Gracefully handle invalid datesAug 11, 2024
Copy link
Member

@xabbuhxabbuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

https://yaml-online-parser.appspot.com/?yaml=date%3A+2024-50-50&type=python yields an error for invalid date and I think we should do the same (i.e. throw aParsException).

@homersimpsons
Copy link
ContributorAuthor

https://yaml-online-parser.appspot.com/?yaml=date%3A+2024-50-50&type=python yields an error for invalid date and I think we should do the same (i.e. throw aParsException).

I changed the code to an exception.

Which branch should I target? 5.4? 6.4? 7.1?

@derrabus
Copy link
Member

5.4

@homersimpsons
Copy link
ContributorAuthor

5.4

Done, There was a conflict onsrc/Symfony/Component/Yaml/Inline.php:\DateTime becomes\DateTimeImmutable in later versions

@derrabus
Copy link
Member

Can you please adjust the PR title and description? They don't match the implemented logic anymore.

homersimpsons reacted with thumbs up emoji

@homersimpsonshomersimpsons changed the title[Yaml] 🐛 Gracefully handle invalid dates[Yaml] 🐛 throw ParseException on invalid dateAug 11, 2024
@homersimpsons
Copy link
ContributorAuthor

Can you please adjust the PR title and description? They don't match the implemented logic anymore.

Done. Tests are failing on twig but I didn't change anything there.

@xabbuh
Copy link
Member

Thank you@homersimpsons.

homersimpsons reacted with thumbs up emoji

@xabbuhxabbuh merged commitd5b0f63 intosymfony:5.4Aug 12, 2024
@homersimpsonshomersimpsons deleted the patch-1 branchAugust 12, 2024 08:41
This was referencedAug 30, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@derrabusderrabusderrabus approved these changes

@xabbuhxabbuhxabbuh approved these changes

@chalasrchalasrchalasr approved these changes

@ycerutoycerutoAwaiting requested review from yceruto

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

6 participants

@homersimpsons@carsonbot@derrabus@xabbuh@stof@chalasr

[8]ページ先頭

©2009-2025 Movatter.jp