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

Match optional parameter with / before the block no longer works #241

Open
MrPropre opened this issue Nov 18, 2019 · 4 comments
Open

Match optional parameter with / before the block no longer works #241

MrPropre opened this issue Nov 18, 2019 · 4 comments
Labels

Comments

@MrPropre
Copy link

MrPropre commented Nov 18, 2019

Before version 2.0 of Altorouter, I could make "/" character optional, if it was before an optional block parameter.

$router->map('GET', '/archives/[lmin:category]?', 'Article#archives');

It doesn't work anymore, the "/" is no longer an option. I can't access /archives, only /archives/.
In the documentation:
.[:format]? // Match an optional parameter 'format' - a / or . before the block is also optional

dannyvankooten added a commit that referenced this issue Nov 23, 2019
@MrPropre
Copy link
Author

MrPropre commented Nov 26, 2019

Hi @dannyvankooten , thank you for the modification, but it doesn't work with this example :

$router->map('GET', '/archives/[lmin:category]?/page-[i:page]?', 'Article#archives');

/archives -> 404
/archives/page-1 -> OK with category = ""
/archives/category -> 404
/archives/category/page-1 -> OK
/archives//page-1 -> OK with category = "" (I can't delete the double slash because I can't check if there is one.)

@dannyvankooten
Copy link
Owner

Hi @PropreCity,

Did that example use to work with AltoRouter < 2.0.0? It looks sensible to me that it doesn't work nowadays, so I'm wondering whether we should re-introduce this behavior in AltoRouter or change it to a custom regex (in your code) instead.

@dannyvankooten
Copy link
Owner

Here's an example:

$router->map('GET', '@/archives/?(?<category>[a-zA-Z]+)?/?(page-)?(?<page>\d+)?', 'Article#archives');

@MrPropre
Copy link
Author

Hello @dannyvankooten,

It doesn't work. But I think it isn't possible to make two parts optional with only one route declaration. I tried with this on FastRoute and it works :

$router->get('/archives[/page-{page:\d+}]', 'Article#archives');
$router->get('/archives/{category:[a-z\-]+}[/page-{page:\d+}]', 'Article#archives');

But it doesn't work with AltoRouter :

$router->get('/archives/page-[i:page]?', 'Article#archives');
$router->get('/archives/[lmin:category]/page-[i:page]?', 'Article#archives');

It works with /archives/page- and /archives/mycategory/page- but not with /archives and /archives/mycategory.

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

No branches or pull requests

2 participants