1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

As Designed Potential bug with XenForo_Router::getSubComponentAction

Discussion in 'Resolved Bug Reports' started by Chris D, Jan 9, 2014.

  1. Chris D

    Chris D XenForo Developer Staff Member

    Given this code example:


    class AddOn_Route_Prefix_Route implements XenForo_Route_Interface
    $_subComponents = array(
    'example' => array(
    'stringId' => 'example_string',
    'actionPrefix' => 'example',
    'controller' => 'AddOn_ControllerPublic_Example'

        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
    $action $router->getSubComponentAction($this->_subComponents$routePath$request$controller);

    $action has different behavior depending on whether there is a trailing slash or not.

    Navigating to this URL:


    Resolves the action as "examplehello". Which produces:
    "The controller AddOn_ControllerPublic_Example does not define an action called Examplehello."

    This URL:


    Resolves the action as "example". Which is correct.

    This inconsistency has the scope to potentially cause confusion if the trailing slash was accidentally omitted.

    I am currently working around this in my own code, using:
            $parts explode('/'$routePath2);
            if (isset(
                if (
    $parts[0] == 'example')
                    if (
    utf8_substr($parts[1], -1) != '/')
    $parts[1] .= '/';

    $routePath implode('/'$parts);
    Which checks and rebuilds the $routePath accordingly to ensure the behavior is the same.
  2. Mike

    Mike XenForo Developer Staff Member

    This is actually how all string-based parameters have worked since 1.0 -- you can see it with add-ons in the control panel for example. This was generally done intentionally, as otherwise it's impossible to have an action that does not take a parameter with a string param prefix.
    Chris D likes this.

Share This Page