🐛 Fix yaml number rendering#179
🐛 Fix yaml number rendering#179javiereguiluz merged 1 commit intosymfony-tools:mainfrom homersimpsons:fix/yaml-number
Conversation
wouterj
left a comment
There was a problem hiding this comment.
Thanks for the fix!
Overwriting the syntax file in this project is indeed the most sensible option (see also my more lengthy response on this matter: #176 (comment)).
The highlight.js syntax file has support for some more number types (especially timestamps, datetimes, etc.). Maybe we can also add those regexes (as a separate number item)? (given the Yaml component supports date strings)
I can add those, but are they supported by |
|
Just tested it. Their regex is pretty eager:
var_dump(Yaml::parse(<<<YAML
v0: 2024-12-07 23:44:39.35677451141299410
v1: 2024-02-3.671 -11
v2: 2024-82T3:66:07 +36
v3: 2024-07-05t6:39:20
v4: 2024-01-30.000
v5: 2024-09-03
YAML
, Yaml::PARSE_DATETIME));will give the following, we can see that symfony won't handle all possible "dates": @wouterj Should I still use their regex or use the one from symfony/yaml? |
This PR was merged into the 5.4 branch. Discussion ---------- [Yaml] 🐛 throw ParseException on invalid date | Q | A | ------------- | --- | Branch? | 5.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | None <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT (found in symfony-tools/docs-builder#179) When parsing the following yaml: ``` date: 6418-75-51 ``` `symfony/yaml` will throw an exception: ``` $ php main.php PHP 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:714 Stack 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 a `ParseException`. Commits ------- 6d71a7e 🐛 throw ParseException on invalid date
|
@wouterj I used the regex from The failure is probably not linked to my changes. I rebased on main, but I still have the error. |
javiereguiluz
left a comment
There was a problem hiding this comment.
Nice work! Thanks @homersimpsons
wouterj
left a comment
There was a problem hiding this comment.
Nice, this is looking great!
Failure is indeed not related to this PR.
|
Merged! Thanks |
Fixes #177
I copied the yaml.json file from https://github.com/scrivo/highlight.php/blob/d1c6b0956a2b0d3efc137e4d8c5bf5c5e220bac1/src/Highlight/languages/yaml.json#L84 and updated the "number" regex to add
_where I think the symfony parser allow them:There may be additional places where the symfony parser allow the
_for numbers.I also updated the tests to add the example from the documentation.