|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-08-14 11:16 UTC] christian at flownative dot com
Description:
------------
If an array key that should be written to YAML contains reserved characters (like ":") these keys need to be escaped in the resulting YAML but aren't.
Test script:
---------------
<?php
$yaml = yaml_emit(array(
'Example' => array (
'Foo:Bar' => 'Baz'
)
));
Expected result:
----------------
$yaml should contain:
Example:
'Foo:Bar': 'Baz'
Actual result:
--------------
$yaml contains:
Example:
Foo:Bar: 'Baz'
which is invalid YAML.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 22:00:01 2025 UTC |
The provided example is perfectly valid YAML: --- Foo:Bar: Baz The canonical encoding for this document would be: %YAML 1.1 --- !!map { ? !!str "Foo:Bar" : !!str "Baz" } In a flow mapping, quoting for simple keys is only needed if the plain scalar value of the key should contain ": " (see <http://yaml.org/spec/1.1/current.html#:%20mapping%20value/>) If this bug was filed due to failing document interoperability with another YAML parser it is likely do to an improper implementation of the YAML 1.1 specification in that product. YAML looks simple but there are a lot of tricky little bits buried in the specification. yaml_emit and yaml_parse mostly rely on LibYAML to get these things right.