Problem/Motivation

After upgrading core to Symfony 5.1 the following deprecation is triggered in Drupal\Tests\Component\Serialization\YamlTest:

Since symfony/yaml 5.1: Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.

The root cause of this is the octal type in core/modules/config/tests/config_test/config/install/config_test.types.yml:

octal: 0775

In the YAML 1.1 spec octal numbers started with an 0 and then any number of digits between 0 and 7.

In YAML 1.2 this has been changed and octal numbers must start with 0o.

Symfony 5.1 now respects YAML 1.2 and has deprecated the older format, but the PHP PECL parser only seems to respect the older format - I can't get it to parse 0o755 for example.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave created an issue. See original summary.

andypost’s picture

Pecl yaml is 1.1 spec that's why core stoped to promote it, there's a set of related issues

catch’s picture

PECL YAML is based on libYAML, and libYAML is slowly moving towards YAML 1.2 support: https://github.com/yaml/libyaml/issues/20

However, it looks unlikely that it'll get there in time for Drupal 10.

Given this is literally only used in test content, could we remove the test coverage and open an issue to add it back once both implementations support octal again?

longwave’s picture

I think removing this - or commenting it out, with an extra comment as to why and a @todo to put it back - is probably the best solution. Parsing octal in YAML is surely a niche case, and as far as I can tell we will never deliberately write octal to YAML in any case, so reading existing hardcoded files is the only place this might be an issue. The only real world use case I know of for octal is as a readable way of storing POSIX file permissions (e.g. 0644 for rw-r--r--).

If we go to Symfony 5 then users who use the Symfony YAML reader will receive the warning. Users who use PECL YAML won't receive any warning, but it won't affect them until PECL upgrades anyway.

If we go straight to Symfony 6 the warning will be skipped, but we can't do anything anyway; if SF6 parses differently from PECL YAML and we support both parsers that is unfortunate but there doesn't seem to be much we can do about it.

andypost’s picture

Btw libyaml already has release of 1.2 as 0.2.3 2020-04-11 so makes sense to check main distributions about shipped version. If pecl extension is not yet ready we can use ffi shim to lib

catch’s picture

Here's a start on a comment, and created the follow-up so I could link to it #3205480: Drop PECL YAML library support in favor of only Symfony YAML.

longwave’s picture

This looks good enough to me except for nits:

  1. +++ b/core/modules/config/tests/config_test/config/install/config_test.types.yml
    @@ -5,6 +5,10 @@ float: 3.14159
    +# Symfony 5.1's YAMl parser issues a deprecation when reading octal with a
    

    YAMl -> YAML

  2. +++ b/core/modules/config/tests/config_test/config/install/config_test.types.yml
    @@ -5,6 +5,10 @@ float: 3.14159
    +# compliant. @todo: revisit parsing of octals once PECL YAML supports YAML 1.2.
    

    octals -> octal (this will satisfy cspell as well!)

longwave’s picture

Status: Needs review » Needs work
abhisekmazumdar’s picture

Status: Needs work » Needs review
FileSize
799 bytes
925 bytes

Updated the suggested changes by @longwave. Kindly review.

Status: Needs review » Needs work

The last submitted patch, 9: 3199691-9.patch, failed testing. View results

catch’s picture

Status: Needs work » Needs review
FileSize
891 bytes
1.65 KB

OK need to change the test too. Copied the comment over there as well.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

I think this the best we can do for now.

alexpott’s picture

The problem with Synfony Yaml and Pecl yaml diverging is that we write all yaml with Symfony and only read with Pecl. So this is going to introduce some awkwardness if there are any octals in contrib... I wonder what will happen to some of the NumericCode's in http://grep.xnddx.ru/node/30888953 - it has stuff like;

NumericCode: 072
longwave’s picture

Aren't those wrong at the moment though? For example, Belize is 084 which isn't valid octal. This would seem to be a good argument for moving to the 0o prefix!

catch’s picture

Seems like three things could happen:

1. Running a version of libYAML which updates the octal parsing to YAML 1.2 while running Drupal 9 - so it gets ahead of Symfony 4's. (this would also break the current test coverage).

2. Running an older version of libYAML with Drupal 10, which is behind Symfony 6.

3. Running a YAML 1.2 compliant version of libYAML with Drupal 10, so parity with Symfony 6.

Since PECL YAML only has minimal requirements for libYAML (and I'm not sure if it exposes the version in use), we could probably only do feature detection in a hook_requirements() or similar to flag any issues. However, I'm really not sure that we want a system status message for YAML octal parsing - and it's one which people are fairly unlikely to have control over. This seems like more of a discussion to have on #3161889: [META] Symfony 6 compatibility though.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 3199691-11.patch, failed testing. View results

Spokje’s picture

Status: Needs work » Reviewed & tested by the community
catch’s picture

Priority: Normal » Critical

Bumping to critical since this blocks Symfony 6 adoption.

alexpott’s picture

One of the problems we have here is if we go from SF4 -> SF6 then Drupal project (custom, contrib, sites) never get the benefit of Symfony's deprecation of 0775<code> octal support - they have to go immediately to <code>0o notation. And if D9 is SF4 and D10 is SF6 then there is no way a project can support both if they are using octal notation. Yes this possibly has zero cases in known contrib projects but still the point is relevant for any other deprecations in SF5.

Should we be adding a deprecation test to allow Sf5 testing and then somehow marking the octal test skipped on Sf6?

longwave’s picture

catch’s picture

We have #3196027: Contrib support solution needed for potential Symfony 4 to 6 upgrade, Symfony 5 only deprecations are not available in Symfony 4 open to discuss the jump between Symfony 4 to 6 for contrib. I'm not sure what a test would gain us here - we can't test the deprecation on Symfony 4 or Symfony 6, and Symfony itself should be testing the Symfony 5 deprecation.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Great to see that #3196027: Contrib support solution needed for potential Symfony 4 to 6 upgrade, Symfony 5 only deprecations are not available in Symfony 4 is open. As this case for octal being used seems v small and not really seen in contrib let's go forward here to make things simpler.

Committed 12c6bfe231 and pushed to 9.2.x. Thanks!

longwave’s picture

Status: Fixed » Reviewed & tested by the community

It doesn't look like this actually got pushed to git.

  • alexpott committed 12c6bfe on 9.2.x
    Issue #3199691 by catch, abhisekmazumdar, longwave: [Symfony 6] Symfony...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Did now - thanks @longwave!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.