Forráskód Böngészése

ZF-10725
Zend_Controller
ViewRenderer not normalizing action name before constructing view script name


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24154 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 éve
szülő
commit
2ef5d71d7f

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

@@ -626,6 +626,9 @@ class Zend_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Action_
         } elseif (null !== $action) {
         } elseif (null !== $action) {
             $vars['action'] = $action;
             $vars['action'] = $action;
         }
         }
+        
+        $replacePattern = array('/[^a-z0-9]+$/', '/^[^a-z0-9]+/');
+        $vars['action'] = preg_replace($replacePattern, '', $vars['action']);
 
 
         $inflector = $this->getInflector();
         $inflector = $this->getInflector();
         if ($this->getNoController() || $this->getNeverController()) {
         if ($this->getNoController() || $this->getNeverController()) {

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

@@ -858,6 +858,36 @@ class Zend_Controller_Action_Helper_ViewRendererTest extends PHPUnit_Framework_T
         $this->assertEquals('B', $b->getViewSuffix());
         $this->assertEquals('B', $b->getViewSuffix());
         $this->assertNotEquals('B', $a->getViewSuffix());
         $this->assertNotEquals('B', $a->getViewSuffix());
     }
     }
+    
+    /**
+     * @group ZF-10725
+     * @dataProvider providerViewScriptNameDoesNotIncludeDisallowedCharacters
+     */
+    public function testViewScriptNameDoesNotIncludeDisallowedCharacters($actionName)
+    {
+        $this->request->setModuleName('default')
+                      ->setControllerName('foo')
+                      ->setActionName($actionName);
+        $controller = new Bar_IndexController($this->request, $this->response, array());
+        $this->helper->setActionController($controller);
+        $scriptName = $this->helper->getViewScript();
+        $this->assertEquals('foo/my-bar.phtml', $scriptName);
+
+    }
+    
+    /**
+     * Data provider for testViewScriptNameDoesNotIncludeDisallowedCharacters
+     * @group ZF-10725
+     * @return array
+     */
+    public function providerViewScriptNameDoesNotIncludeDisallowedCharacters()
+    {
+        return array(
+            array('myBar-'),
+            array('-myBar'),
+            array('-myBar-')
+        );
+    }
 
 
     protected function _normalizePath($path)
     protected function _normalizePath($path)
     {
     {