Zend Framework

Zend_Config_Yaml should ignore comments

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.11.6
  • Component/s: Zend_Config
  • Labels:
    None

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!

  1. ZF-11329_fix.patch
    29/Apr/11 1:18 AM
    2 kB
    Adam Lundrigan
  2. ZF-11329_reproduce.patch
    29/Apr/11 1:18 AM
    2 kB
    Adam Lundrigan

Issue Links

Activity

Hide
Adam Lundrigan added a comment -

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

Show
Adam Lundrigan added a comment - 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
Hide
Adam Lundrigan added a comment -

Fix in trunk r23882

Show
Adam Lundrigan added a comment - Fix in trunk r23882
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - Fixed in r23882 & r23951 in trunk and r23952 in release branch 1.11

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: