As designed Issues with API router

Jake B.

Well-known member
Affected version
2.1.10
I've got an example route with the following:

Code:
Route Prefix: thtest
Sub-name: sessions/
Route format: sessions/:+str<session_id>/
Controller: ThemeHouse\Test:Session

It works fine for routing something like:

GET /api/thtest/sessions/abc123/test
However, it isn't able to route GET /api/thtest/sessions/abc123 for some reason. Looks to be an issue with the regex that gets generated in \XF\Mvc\Router::generateMatchRegexInner
 
This isn't really unexpected and I would likely say it's as designed. String parameters require a trailing /. This allows a differentiation between route/action and route/param/ (with implied index/empty action name). This has been a standard approach of the XF routing system going back to XF1.

We have made some adjustments here in some places in XF, though they actually create theoretical ambiguity, but they also try to deal with the uncontrolled way in which links to pages may be created. In an API context, I think it's quite reasonable to expect the API accessor to call code/routes in the expected way and for it to simply fail if they don't.
 
Top Bottom