php.net |  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
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] bd808@php.net
-Status: Open +Status: Not a bug
 [2015-09-09 02:47 UTC] bd808@php.net
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.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Jan 26 17:01:25 2020 UTC