FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Using regex in fos_js_routing.routes_to_expose no longer works correctly in 2.3.0 #355

Closed kriswillis closed 5 years ago

kriswillis commented 5 years ago

Since updating from 2.2.2 to 2.3.0, regex defined in fos_js_routing.routes_to_expose within config.yml are no longer matching our routes.

We're using the following patterns:

fos_js_routing:
    routes_to_expose: ["_api_", "_modal$", "_list$"]

Symfony 3.4.22 JsRoutingBundle 2.3.0

Rolling back to 2.2.2 exposes the routes correctly again.

krixon commented 5 years ago

Same here, this seems to have been introduced in ce741512474c654d703833d263d337da28e09fe1

protected function getDomainByRouteMatches($matches, $name)
{
    $matches = array_filter($matches, function($match) {
        return !empty($match);
    });

    $matches = array_flip(array_intersect_key($matches, array_flip($this->availableDomains)));

    return isset($matches[$name]) ? $matches[$name] : null;
}

Here $name is the full route name, but $matches contains the part of the route name which matches the regex, not the entire route name.

For example, given the pattern ^foo_ and a route named foo_bar, $matches would contain only foo_.

You can work around this regression by ensuring the pattern in your config specifically matches the entire route name rather than just part of it:

routes_to_expose:
    - '^foo_.+'
tobias-93 commented 5 years ago

Fixed using #350