6.0.0-alpha10
5/14/25

[#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 (at) naberezny (dot) com
Requester apinstein (at) mac (dot) com
Created 06/09/2008 (6183 days ago)
Due
Updated 09/24/2010 (5346 days ago)
Assigned 05/02/2009 (5856 days ago)
Resolved
Milestone
Patch No

History
09/24/2010 10:22:22 PM Jan Schneider Version ⇒ Git master
 
05/02/2009 02:40:56 AM Chuck Hagenbuch Comment #7
Taken from Chuck Hagenbuch
State ⇒ Assigned
Reply to this comment
Thanks. Mike, passing this back to you.
05/02/2009 02:37:57 AM apinstein (at) mac (dot) com Comment #6 Reply to this comment
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.



Alan
05/02/2009 02:05:15 AM Chuck Hagenbuch Comment #5
State ⇒ Resolved
Reply to this comment
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.
04/24/2009 06:10:24 AM apinstein (at) mac (dot) com Comment #4
New Attachment: yaml-comment.patch Download
Reply to this comment
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.



LMK,

Alan
04/24/2009 04:34:58 AM Chuck Hagenbuch Comment #3
State ⇒ Feedback
Reply to this comment
Well, you could supply a unit test, to help prove the patch was 
correct and not breaking anything else.
04/24/2009 01:18:26 AM apinstein (at) mac (dot) com Comment #2 Reply to this comment
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?
06/10/2008 12:09:31 AM Chuck Hagenbuch Assigned to Mike Naberezny
 
06/09/2008 07:49:45 AM Jan Schneider Assigned to Chuck Hagenbuch
State ⇒ Assigned
 
06/09/2008 05:12:28 AM apinstein (at) mac (dot) com Comment #1
Priority ⇒ 1. Low
Type ⇒ Bug
Summary ⇒ yaml dumper should quote values with comments
Queue ⇒ Horde Framework Packages
Milestone ⇒
Patch ⇒ No
State ⇒ Unconfirmed
Reply to this comment
I have run into a problem with dumping PHP arrays that contain "#" 
characters, which is a comment signifier in YAML. I have a proposed 
patch:



--- /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.

Saved Queries