Browse Source

ZF-10725: normalize action before determining view script

- Applied patch from Adam L.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24199 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 14 years ago
parent
commit
ba9f777e52

+ 8 - 0
library/Zend/Controller/Action/Helper/ViewRenderer.php

@@ -630,6 +630,14 @@ class Zend_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Action_
         $replacePattern = array('/[^a-z0-9]+$/', '/^[^a-z0-9]+/');
         $vars['action'] = preg_replace($replacePattern, '', $vars['action']);
 
+        // Remove non-alphanumeric characters from action name
+        // see ZF-10725
+        $vars['action'] = preg_replace(
+            array('/[^a-z0-9]+$/', '/^[^a-z0-9]+/'),
+            array('', ''),
+            $vars['action']
+        );
+
         $inflector = $this->getInflector();
         if ($this->getNoController() || $this->getNeverController()) {
             $this->_setInflectorTarget($this->getViewScriptPathNoControllerSpec());

+ 13 - 0
tests/Zend/Controller/Action/Helper/ViewRendererTest.php

@@ -827,6 +827,19 @@ class Zend_Controller_Action_Helper_ViewRendererTest extends PHPUnit_Framework_T
         $body = $this->response->getBody();
         $this->assertContains('fooUseHelper invoked', $body, 'Received ' . $body);
     }
+    /**
+     * @group ZF-10725
+     */
+    public function testThatCharactersStrippedFromActionNameByDispatcherAreAlsoStrippedFromViewScriptName()
+    {
+        $this->request->setModuleName('default')
+                      ->setControllerName('foo')
+                      ->setActionName('-myBar-');
+        $controller = new Bar_IndexController($this->request, $this->response, array());
+        $this->helper->setActionController($controller);
+        $scriptName = $this->helper->getViewScript();
+        $this->assertEquals('foo/my-bar.phtml', $scriptName);
+    }
 
     public function testCorrectViewHelperPathShouldBePropagatedWhenSubControllerInvokedInDefaultModule()
     {