ZF-11329: Zend_Config_Yaml should ignore comments

Description

It seems the only comments getting properly ignored are those that begin a line. Comments after a value incorrectly remain as part of the value

Example:

Good -

resources: frontController: controllerDirectory: APPLICATION_PATH/controllers

Bad - resources: frontController: controllerDirectory: APPLICATION_PATH/controllers #heynow!

Comments

Attached a testsuite patch which reproduces the issue based upon the OP's description of the problem.

Run Result:


There was 1 failure:

1) Zend_Config_YamlTest::testAllowsInlineCommentsInValuesUsingHash
--- Expected
+++ Actual
@@ @@
-APPLICATION_PATH/controllers
+APPLICATION_PATH/controllers #heynow!

Attached a fix patch which includes the reproduction testsuite and the suggested fix:


--- library/Zend/Config/Yaml.php        (revision 23879)
+++ library/Zend/Config/Yaml.php        (working copy)
@@ -315,7 +315,7 @@
                 // key: value
                 if (strlen($m[2])) {
                     // simple key: value
-                    $value = $m[2];
+                    $value = rtrim(preg_replace("/#.*$/", "", $m[2]));
                     // Check for booleans and constants
                     if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) {
                         $value = true;

Full framework test suite passes after change is performed

Fix in trunk r23882

Fixed in r23882 & r23951 in trunk and r23952 in release branch 1.11