auraphp / Aura.Router

A web router implementation for PHP.
http://auraphp.com/packages/3.x/Router/
MIT License
494 stars 74 forks source link

Basepath concatenation could be improved #154

Open KernelDeimos opened 7 years ago

KernelDeimos commented 7 years ago

Currently, basepath is simply concatenated with the path regex used in a route.

This can lead to confusing results when, say, basepath is websites/ and the route is /testpage, since Aura.Router currently will concatenate this to websites//testpage.

I have implemented a fix for this on my fork as follows:

// Trim leading and following slashes from basepath
$basePart = trim($this->basepath, '/');

// Trim leading slash from route path
$routePart = ltrim($this->route->path, '/');

// Join basepath and route with forwardslash
$this->regex = '/' . implode('/', array($basePart, $routePart));

This works great, but I found out it's too lenient. When I ran phpunit I noticed it breaks 12 test cases :/

I'll try to figure out a fix that doesn't cause this issues, but in the meantime I'll post this issue in case I forget.

KernelDeimos commented 7 years ago

OH.... This is very complicated to do because the route regex may or may not match a leading slash depending on the route the user enters.

ncou commented 5 years ago

some router use this code on the basePath : $this->basePath = rtrim($basePath, '/');

harikt commented 2 years ago

Hi,

I am sorry for being late. Just a quick question is this still a problem or have a fix ?

We are in the process of making 4.x . In case this is an issue please report back. Else do close it.

Thank you.