Aura.Router icon indicating copy to clipboard operation
Aura.Router copied to clipboard

Basepath concatenation could be improved

Open KernelDeimos opened this issue 7 years ago • 3 comments

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 avatar Oct 23 '17 03:10 KernelDeimos

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.

KernelDeimos avatar Oct 24 '17 23:10 KernelDeimos

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

ncou avatar Jun 22 '19 07:06 ncou

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.

harikt avatar Jan 26 '22 10:01 harikt