ZF-11329: Zend_Config_Yaml should ignore comments

Issue Type: Bug Created: 2011-04-27T19:12:38.000+0000 Last Updated: 2011-05-19T14:21:17.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: Dan Berman (panckreous) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Config

Related issues: - ZF-11384

Attachments: - ZF-11329_fix.patch


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


Good -

resources: frontController: controllerDirectory: APPLICATION_PATH/controllers

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


Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T01:18:59.000+0000

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

Run Result:

<pre class="highlight">
There was 1 failure:

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

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

<pre class="highlight">
--- 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

Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T01:22:40.000+0000

Fix in trunk r23882

Posted by Ralph Schindler (ralph) on 2011-05-03T05:48:10.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.