ZF-2538: Zend_Filter_Inflector::filter() fails with all numeric folder on Windows



I think we've found a bug in Zend_Filter_Inflector::filter() when using Windows and a module directory that contains a folder consisting entirely of numbers.

The problem manifests itself on line 150 of Inflector.php:

$inflectedTarget = preg_replace(array_keys($processedParts), array_values($processedParts), $this->_target);

In our case input data is: $processedParts: array(2) { ["#:suffix#"] => "phtml" ["#:moduleDir#"] => "D:\htdocs\HEAD\24074\app\modules\default" }

$this->_target : ":moduleDir/views"

And the result is:

$inflectedTarget: "D:\htdocs\HEAD074\app\modules\default/views"

If we use a module dir of "D:/htdocs/HEAD/24074/app/modules" then the problem goes away. Similarly a module dir of "D:\htdocs\HEAD\a24074\app\modules\default" also works.

Note that it doesn't matter what the number is, in all cases, the first two digits, along with the precending backslash are removed. I suspect it's related to preg_replace's parameter substitution.


Assigning to Ralph

Yes, I found the same problem, simple workaround is (tested only on windows)

$ diff -Naur \
 /c/Program\ Files/Apache\ Group/Apache2/htdocs/zftrunk/library/Zend/Filter/Inflector.php.orig  \
 /c/Program\ Files/Apache\ Group/Apache2/htdocs/zftrunk/library/Zend/Filter/Inflector.php 
--- /c/Program Files/Apache Group/Apache2/htdocs/zftrunk/library/Zend/Filter/Inflector.php.orig Tue Dec 11 14:29:34 2007
+++ /c/Program Files/Apache Group/Apache2/htdocs/zftrunk/library/Zend/Filter/Inflector.php      Tue Feb  5 08:00:54 2008
@@ -443,6 +443,7 @@
                    $processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = $processedPart;
            } elseif (is_string($ruleValue)) {
+                $ruleValue=str_replace("\\","\\\\",$ruleValue);
                 $processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = $ruleValue;

FIxed in r8036.

Added str_replace() to disable possible backreference like syntax inside replacement strings.