[#6861] yaml dumper should quote values with comments
Summary yaml dumper should quote values with comments
Queue Horde Framework Packages
Queue Version Git master
Type Bug
State Assigned
Priority 1. Low
Owners mike@naberezny.com
Requester apinstein@mac.com
Created 2008-06-09 (4879 days ago)
Updated 2010-09-24 (4042 days ago)
Assigned 2009-05-02 (4552 days ago)
Patch No

apinstein@mac.com 2008-06-09 05:12:28
I have run into a problem with dumping PHP arrays that contain "#" 
characters, which is a comment signifier in YAML. I have a proposed 

--- /Users/alanpinstein/Dumper.php.orig 2008-06-09 01:08:54.000000000 -0400

+++ /opt/local/lib/php/Horde/Yaml/Dumper.php    2008-06-09 
01:08:57.000000000 -0400

@@ -153,6 +153,11 @@

          $spaces = str_repeat(' ', $indent);

+        // quote strings if necessary

+        if (strchr($value, '#')) {

+            $value = "'{$value}'";

+        }


          if (is_int($key)) {

              // It's a sequence.

              $string = $spaces . '- ' . $value . "\n";

There might be more cases, and I don't know if this breaks in the case 
of folded code, but it's a start for you hopefully. This is a pretty 
important bug I think because it really breaks YAML dumping if you 
have this character in a string, which is a common occurrence.

apinstein@mac.com 2009-04-24 01:18:26
How is this still not fixed 1 yr later? I even supplied a patch! Very 
frustrating to remember i have to work around this bug every time I 
set up a new machine...

Is there anything I can do to further this?

Chuck Hagenbuch <chuck@horde.org> 2009-04-24 04:34:58
Well, you could supply a unit test, to help prove the patch was 
correct and not breaking anything else.

apinstein@mac.com 2009-04-24 06:10:24
I have written up a patch with some tests (attached).

I have the dumper side working, but something odd is happening on the 
loading side. There is an extra \n at the end. I am not sure why.... 
maybe you could figure that part out.



Chuck Hagenbuch <chuck@horde.org> 2009-05-02 02:05:15
Committed, thanks; I don't see any tests fail, so I'm closing this... 
if you have a failing test for the extra \n, please comment and I'll 
reopen and/or fix.

apinstein@mac.com 2009-05-02 02:37:57
I just figured out why the tests were failing for me. I have syck 
installed, and just realized that Horde calls syck, which outputs 
different YAML than Horde/Yaml does. When I disabled syck temporarily 
all of the tests pass.

FWIW, you might consider making your tests do round-trip tests like so:

$this->assertEquals($inputPhpStruct, load(dump($inputPhpStruct)))

Also you might consider an option to "disable" syck use and use this 
option for the tests to ensure that testing is actually testing the 
Horde/Yaml code!

Thanks for accepting the patch.


Chuck Hagenbuch <chuck@horde.org> 2009-05-02 02:40:56
Thanks. Mike, passing this back to you.