Zend Framework

Undefined index error when one of the letters in the module name has a wrong case

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.10.5, 1.10.8
  • Fix Version/s: None
  • Component/s: Zend_Controller
  • Labels:
    None

Description

We've got a module named "manager". It works with /manager URI. However, when someone opens /Manager, we get:

ErrorException with message "Undefined index: Manager" in /Users/ikr/Sites/ch.xyz.local/library/Zend/Controller/Dispatcher/Standard.php on line 384

#0 /Users/ikr/Sites/ch.xyz.local/library/Zend/Controller/Dispatcher/Standard.php(384): __lambda_func(8, 'Undefined index...', '/Users/ikr/Site...', 384, Array)
#1 /Users/ikr/Sites/ch.xyz.local/library/Zend/Controller/Dispatcher/Standard.php(204): Zend_Controller_Dispatcher_Standard->getControllerClass(Object(Zend_Controller_Request_Http))
#2 /Users/ikr/Sites/ch.xyz.local/library/Zend/Controller/Dispatcher/Standard.php(244): Zend_Controller_Dispatcher_Standard->isDispatchable(Object(Zend_Controller_Request_Http))
#3 /Users/ikr/Sites/ch.xyz.local/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#4 /Users/ikr/Sites/ch.xyz.local/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#5 /Users/ikr/Sites/ch.xyz.local/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#6 /Users/ikr/Sites/ch.xyz.local/public/index.php(18): Zend_Application->run()
#7 {main}

I guess, the ZF site has the same problem. Try http://framework.zend.com/mAnual/en/ instead of http://framework.zend.com/manual/en/

I'd expect either a 404 instead, or a dispatch to the correct module, ignoring the case in its name.

Activity

Hide
Thomas Lamy added a comment -

The issue is still present.

I am new to ZF, so I'm not sure about case rules... For myself, I fixed it by
modifying Zend_Controller_Request_Abstract->getModuleName() and ->setModuleName() to:

/**

  • Retrieve the module name
    *
  • @return string
    */
    public function getModuleName()
    {
    if (null === $this->_module) { $this->_module = strtolower($this->getParam($this->getModuleKey())); }

return $this->_module;
}

/**

  • Set the module name to use
    *
  • @param string $value
  • @return Zend_Controller_Request_Abstract
    */
    public function setModuleName($value) { $this->_module = strtolower($value); return $this; }
Show
Thomas Lamy added a comment - The issue is still present. I am new to ZF, so I'm not sure about case rules... For myself, I fixed it by modifying Zend_Controller_Request_Abstract->getModuleName() and ->setModuleName() to: /**
  • Retrieve the module name *
  • @return string */ public function getModuleName() { if (null === $this->_module) { $this->_module = strtolower($this->getParam($this->getModuleKey())); }
return $this->_module; } /**
  • Set the module name to use *
  • @param string $value
  • @return Zend_Controller_Request_Abstract */ public function setModuleName($value) { $this->_module = strtolower($value); return $this; }
Hide
Thomas Lamy added a comment -

Unified diff against 1.10.8 release

Show
Thomas Lamy added a comment - Unified diff against 1.10.8 release
Hide
Thomas Lamy added a comment -

Added found in version 1.10.8

Show
Thomas Lamy added a comment - Added found in version 1.10.8
Hide
Ivan Krechetov added a comment -

http://framework.zend.com/index$ also results in response status 500, instead of 404

Show
Ivan Krechetov added a comment - http://framework.zend.com/index$ also results in response status 500, instead of 404
Hide
Thomas Lamy added a comment -

Ivan, this is a different issue.

My patch worksforme(tm), for mixed case module names. That's what this particular issue is all about.
There may be other issues (like your last comment, and maybe also my workaround patch) which have to be fixed in the dispatcher's sanitizing and name mangling in general, and for all route related items (module, controller, action).

Show
Thomas Lamy added a comment - Ivan, this is a different issue. My patch worksforme(tm), for mixed case module names. That's what this particular issue is all about. There may be other issues (like your last comment, and maybe also my workaround patch) which have to be fixed in the dispatcher's sanitizing and name mangling in general, and for all route related items (module, controller, action).
Hide
Brandon Dahler added a comment -

Below is a unified diff for 1.11.11 to fix. Resolves all problems by changing the path via strtolower in the Zend_Controller_Router_Route_Module router. Allows for any kind of capitalization desired.

The only thing that might be wanted (technically out of scope for this bug) is setting the specifically wanted casing for assemble when adding the module to the controller directories. This would be wanted for SEO purposes.

— /Zend/Controller/Router/Route/Module.php Wed Jan 25 16:42:42 2012
+++ /Zend/Controller/Router/Route/Module.php Tue Jan 31 20:26:25 2012
@@ -156,8 +156,8 @@
if ($path != '') {
$path = explode(self::URI_DELIMITER, $path);

  • if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
  • $values[$this->_moduleKey] = array_shift($path);
    + if ($this->_dispatcher && $this->_dispatcher->isValidModule(strtolower($path[0]))) { + $values[$this->_moduleKey] = strtolower(array_shift($path)); $this->_moduleValid = true; }
Show
Brandon Dahler added a comment - Below is a unified diff for 1.11.11 to fix. Resolves all problems by changing the path via strtolower in the Zend_Controller_Router_Route_Module router. Allows for any kind of capitalization desired. The only thing that might be wanted (technically out of scope for this bug) is setting the specifically wanted casing for assemble when adding the module to the controller directories. This would be wanted for SEO purposes. — /Zend/Controller/Router/Route/Module.php Wed Jan 25 16:42:42 2012 +++ /Zend/Controller/Router/Route/Module.php Tue Jan 31 20:26:25 2012 @@ -156,8 +156,8 @@ if ($path != '') { $path = explode(self::URI_DELIMITER, $path);
  • if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
  • $values[$this->_moduleKey] = array_shift($path); + if ($this->_dispatcher && $this->_dispatcher->isValidModule(strtolower($path[0]))) { + $values[$this->_moduleKey] = strtolower(array_shift($path)); $this->_moduleValid = true; }
Hide
Brandon Dahler added a comment -

Fix for above diff to display correctly.

--- /Zend/Controller/Router/Route/Module.php	Wed Jan 25 16:42:42 2012
+++ /Zend/Controller/Router/Route/Module.php	Tue Jan 31 20:26:25 2012
@@ -156,8 +156,8 @@
         if ($path != '') {
             $path = explode(self::URI_DELIMITER, $path);
 
-            if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
-                $values[$this->_moduleKey] = array_shift($path);
+            if ($this->_dispatcher && $this->_dispatcher->isValidModule(strtolower($path[0]))) {
+                $values[$this->_moduleKey] = strtolower(array_shift($path));
                 $this->_moduleValid = true;
             }
Show
Brandon Dahler added a comment - Fix for above diff to display correctly.
--- /Zend/Controller/Router/Route/Module.php	Wed Jan 25 16:42:42 2012
+++ /Zend/Controller/Router/Route/Module.php	Tue Jan 31 20:26:25 2012
@@ -156,8 +156,8 @@
         if ($path != '') {
             $path = explode(self::URI_DELIMITER, $path);
 
-            if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
-                $values[$this->_moduleKey] = array_shift($path);
+            if ($this->_dispatcher && $this->_dispatcher->isValidModule(strtolower($path[0]))) {
+                $values[$this->_moduleKey] = strtolower(array_shift($path));
                 $this->_moduleValid = true;
             }

People

Vote (3)
Watch (3)

Dates

  • Created:
    Updated: