Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Symfony\Component\Yaml\Inline::evaluateScalar() breaks ISO 8601 dates #6275

Closed
bartfeenstra opened this Issue · 5 comments

4 participants

@bartfeenstra

Symfony\Component\Yaml\Inline::evaluateScalar() uses Symfony\Component\Yaml\Inline::getTimestampRegex() to determine whether a scalar value contains a date in what seems to be the ISO 8601 format (getTimestampRegex() is badly documented) and if it does, it converts it to a Unix timestamp.
The problem is that this conversion is conceptually impossible for a number of reasons:

  • ISO 8601 dates and Unix timestamps use different formats. Converting one to the other may break systems that expect a particular format.
  • Unix timestamps do not support dates before 1970, while ISO 8601 does. This means data loss.

Suggested solution: remove the feature entirely.

@stof
Collaborator

The feature should not be removed as handling ISO 8601 values a dates is part of the YAML spec. If you want to keep the string, you have to quote it.

@bartfeenstra

I might not be a YAML expert, but how is converting a value that can or cannot (e.g. dates before 1970) be converted to a Unix timestamp to a Unix timestamp part of the specifications? I did a quick search of the 1.0, 1.1 and 1.2 documentation and couldn't find anything about special handling for ISO 8601 or Unix timestamps.

@asm89

@bartfeenstra Dates before 1970 are represented by negative numbers. See the PR I created with a test showing that dates before 1970 work.

Are you having issues with this?

@fabpot fabpot referenced this issue from a commit
@fabpot fabpot merged branch asm89/yaml-inline (PR #6277)
This PR was merged into the master branch.

Commits
-------

2f07966 [Yaml] Add test showing that dates before 01 Jan 1970 are correctly parsed

Discussion
----------

[Yaml] Add test showing that dates before 01 Jan 1970 are correctly parsed

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

Adds a test related to issue #6275, showing that the Yaml inline parsing supports ISO 8601 dates before 1980.
8feda90
@bartfeenstra

It appears that YYYY-MM-DD formats need to be quoted so Yaml doesn't convert them. YYYY-MM formats can be unquoted. My problems occured after manually altering some configuration files and not quoting YYYY-MM-DDD formats. A classic example of pebkac.

Thank you, stof and asm89, for your time spent on this issue!

Now that my issues are solved, I still have a few questions though:

  • Unix timestamps in PHP, which are essentially 32bits signed integers, have a very limited minimum value. -2147483647 (minimum value) / 86400 (number of seconds in a day) / 365 (days in a year) = roughly 68 years before 1970, so when converting any ISO8601 date before roughly 1902 on a 32bit system, this should result in an overflow. On 64bit systems the range of a Unix timestamp exceeds that of the default ISO 8601 format and this problem does not occur.
  • Why does Yaml convert some date formats (Symfony\Component\Yaml\Inline::getTimestampRegex() says "Unix timestamp", which is incorrect, not does it really describe what the pattern should match), but not all? To be more specific: why does it convert YYYY-MM-DD, but not YYYY-MM?
@stof
Collaborator

@bartfeenstra because of the format specified in the YAML spec for timestamps: http://www.yaml.org/spec/1.2/spec.html#id2761573

@fabpot fabpot closed this in 04d95a5
@mmucklo mmucklo referenced this issue from a commit
@fabpot fabpot merged branch asm89/yaml-inline (PR #6277)
This PR was merged into the master branch.

Commits
-------

2f07966 [Yaml] Add test showing that dates before 01 Jan 1970 are correctly parsed

Discussion
----------

[Yaml] Add test showing that dates before 01 Jan 1970 are correctly parsed

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

Adds a test related to issue #6275, showing that the Yaml inline parsing supports ISO 8601 dates before 1980.
26a115f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.