Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL with a "dot" will not work if the empty match type regex is used. #221

Open
ncou opened this issue Jun 19, 2018 · 2 comments
Open

URL with a "dot" will not work if the empty match type regex is used. #221

ncou opened this issue Jun 19, 2018 · 2 comments

Comments

@ncou
Copy link

ncou commented Jun 19, 2018

Hi,

Very nice work. When using you lib, i found what it seems like a little problem.
I have a dot in my url, and altorouter doesn't seems to find a match (for example if you want to have he version of your api in the url => https://api/1.1/user.json).

i used the empty match type regex for the id :

$router->map('GET','/users/[:id]', 'users#show', 'users_show');

But it looks like the dot is not working because the empty match type regex is : '[^/\.]++' https://github.com/dannyvankooten/AltoRouter/blob/master/AltoRouter.php#L29

This mean the regex will stop at the character "/" or "." the dot is surely used when there is an extension in the uri.
But if you read the documentation :

[:action] // Match anything up to the next / or end of the URI as 'action'

It doesn't say the dot will be used in the matching process.
I think the empty regex should be : '[^/]++' to just stop at the end of the line or at the next slash.

Am i missing something ?

@koenpunt
Copy link
Collaborator

koenpunt commented Sep 26, 2018

I think this is a documentation error, because it's often useful to match an extension separate from the path/filename.

If you like to change the default behavior, you can do so by overriding the match type

$router->setMatchTypes([
  '' => '[^/]++',
]);

@ncou
Copy link
Author

ncou commented Sep 26, 2018

yes probably an error in the documentation, but this should be clarified.
Thank you for the piece of code, i made a router using Altorouter and i have already modified the code the change the regex.

have a good day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants