Problem/Motivation
What are the steps required to reproduce the bug?
Do something that requires Drupal to process a YAML file which only contains comments.
In my case it was installing a theme which has multiple YAML files, one of which holds a commented out example configuration.
Do so in an environment which has PECL YAML installed, otherwise Drupal will use the Symfony YAML component which appears to be more standards compliant for this aspect.
What behavior were you expecting?
No errors, because YAML files with only comments are valid. See http://yaml.org/spec/current.html#id2527268
What happened instead?
A PHP warning was thrown.
Drupal\Component\Serialization\Exception\InvalidDataTypeException: yaml_parse(): end of stream reached without finding document 0 in [error]
/var/www/docroot/core/lib/Drupal/Component/Serialization/YamlPecl.php:72
Stack trace:
#0 [internal function]: Drupal\Component\Serialization\YamlPecl::errorHandler(2, 'yaml_parse(): e...', '/var/www/docro...', 54, Array)
#1 /var/www/docroot/core/lib/Drupal/Component/Serialization/YamlPecl.php(54): yaml_parse('# layout_name_g...', 0, 0, Array)Proposed resolution
Catch the specific error message and treat it just like we already treated empty YAML files since #1920902: Add a Drupal Yaml wrapper so we can default to PECL Yaml component if it is available
Remaining tasks
Patch review.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | interdiff-3003300-8.patch | 940 bytes | swentel |
| #8 | 3003300-8.patch | 2.29 KB | swentel |
Comments
Comment #2
pieterdcExtended existing test to cover scope of this issue. Patch attached.
Comment #4
pieterdcOk, so that test run proved that current Drupal core doesn't catch PECL YAML its failure to accept YAML files with only comments.
Newly attached patch implements the proposed solution from the issue description. Let's see if that fixes the extended test.
Comment #5
mile23Coming here from #2982684-98: Add a composer scaffolding plugin to core
Patch still applies, re-running test.
Comment #8
swentel commentedStill applies fine to 9.3.x as well.
Changed the patch with some minor code styling (catch and else on a new line - unless I miss something here)
Comment #9
swentel commentedCancelled the interdiff test, sorry for the noise.
Comment #11
neclimdulPecl YAML fixed this over 3 years ago. Is there a reason to still apply this patch?
This isn't even valid anymore. Should probably follow up to remove it.
Comment #14
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
This will need a test case to show the issue.
Comment #16
quietone commentedThis was a bugsmash triage target today. Both chx and mstrlen recommend that this is closed as outdated.