|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70267 yaml_emit doesn't escape keys
Submitted: 2015-08-14 11:16 UTC Modified: 2015-09-09 02:47 UTC
From: christian at flownative dot com Assigned:
Status: Not a bug Package: yaml (PECL)
PHP Version: Irrelevant OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: christian at flownative dot com
New email:
PHP Version: OS:


 [2015-08-14 11:16 UTC] christian at flownative dot com
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:

$yaml = yaml_emit(array(
  'Example' => array (
    'Foo:Bar' => 'Baz'

Expected result:
$yaml should contain:

  'Foo:Bar': 'Baz'

Actual result:
$yaml contains:

  Foo:Bar: 'Baz'

which is invalid YAML.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-14 11:17 UTC] christian at flownative dot com
-Package: yami +Package: yaml
 [2015-08-14 11:17 UTC] christian at flownative dot com
Tagged with wrong pecl extension, now correct.
 [2015-09-09 02:47 UTC]
-Status: Open +Status: Not a bug
 [2015-09-09 02:47 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 <>)

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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Jan 30 02:03:43 2023 UTC