[#6861] yaml dumper should quote values with comments
Summary yaml dumper should quote values with comments
Queue Horde Framework Packages
Queue Version FRAMEWORK_3
Type Bug
State Assigned
Priority 1. Low
Owners Mike Naberezny <mike (at) naberezny (dot) com>
Requester apinstein (at) mac (dot) com
Created 06/09/08 (641 days ago)
Due
Updated 05/01/09 (315 days ago)
Assigned 05/01/09 (315 days ago)
Resolved
Attachments yaml-comment.patch Download
Milestone
Patch No

History
05/01/09 Chuck Hagenbuch Comment #7
State ⇒ Assigned
Taken from Chuck Hagenbuch
Reply to this comment
Thanks. Mike, passing this back to you.
05/01/09 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/01/09 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/09 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/09 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/23/09 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/09/08 Chuck Hagenbuch Assigned to Mike Naberezny
 
06/09/08 Jan Schneider State ⇒ Assigned
Assigned to Chuck Hagenbuch
 
06/09/08 apinstein (at) mac (dot) com Comment #1
State ⇒ Unconfirmed
Patch ⇒
Milestone ⇒
Queue ⇒ Horde Framework Packages
Summary ⇒ yaml dumper should quote values with comments
Type ⇒ Bug
Priority ⇒ 1. Low
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.