Open pmarien opened 5 years ago
Ended using preg_quote(trim($prefix,'/'),'/')
to make it work for subpaths.
I fixed it by escaping the /
within the $prefix
. preg_quote
didn't work for me:
preg_match(
'/^(([a-zA-Z0-9\_\-\.\/]+.php)(\/)|)(' . str_replace('/','\\/',$this->apiPrefix) . ')([\/a-zA-Z0-9\_\-\.]+)$/',
trim($path, '/'),
$matches
);
Let's look at where url/api prefix is eventually used \Enm\JsonApi\Model\Request\Request::parseUriPath:
So the prefix is used in a regex using
/
as open/close characters. This basically means the prefix cannot contain that character (unless escaped).Why does the default/test implementation work? Because the prefix is trimmed and the example doesn't try subpaths.
What's the problem with this?
/
character is very common in paths, unlike other regex special characters{type}
somewhere in the string when in fact, it doesn't seem to be the case'\\/api'
insteadWhat are the solutions?
#theregex#
)preg_match('/...' . preg_quote(...) . '.../'...
)api(-v\d+)
will now not work)/
and maybe example code for subpaths)url_prefix
=>url_prefix_regex
)See original issue: https://github.com/eosnewmedia/JSON-API-Server/issues/9