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

Dynamic route parameters not supporting non-ascii characters #35

Closed
Robinjoeh opened this issue Jul 19, 2022 · 4 comments
Closed

Dynamic route parameters not supporting non-ascii characters #35

Robinjoeh opened this issue Jul 19, 2022 · 4 comments

Comments

@Robinjoeh
Copy link

Stumbled across another issue which is related to the previous issue about non-ascii characters not being parsed correctly by the router (that was fixed in this commit).

Imagine the following scenario:

$router->addRoute('/язык/[s:language]/', function($route, $variables){});

Where language equals русский, meaning the final URL is /язык/русский. This now results in an error The processor was not found for the route.

Is it possible to add support for this in the variables?

@alexdodonov
Copy link
Owner

Hi!

Please check v.1.5.1

Hope it is exactly what you need.

@Robinjoeh
Copy link
Author

Robinjoeh commented Jul 25, 2022

Nice one!
I just tried to test 1.5 and 1.5.1 as well, it seems something with url parameters was changed and I'm getting an error. It's a normal and basic route, i.e. /user/[i:id]. Seems to be the same for all URLs with variables, only the ones without work. Any idea?

Message: 'Unknown named parameter $id'

Stack trace:
#0 vendor/mezon/router/Mezon/Router/RouterBase.php(223): call_user_func_array()
#1 vendor/mezon/router/Mezon/Router/UrlParserBase.php(111): Mezon\Router\RouterBase->getMiddlewareResult()
#2 vendor/mezon/router/Mezon/Router/RouterBase.php(91): Mezon\Router\Router->executeHandler()
#3 vendor/mezon/router/Mezon/Router/Router.php(34): Mezon\Router\RouterBase->callRoute()
#4 [internal function]: Mezon\Router\Router->callRoute()
Thrown in '/vendor/mezon/router/Mezon/Router/RouterBase.php' on line 223

I suppose it is related to middlewares being refactored in 1.5, as it worked fine in 1.4. Is the below still correct?

$router->registerMiddleware('*', function(string $route, array $parameters = []) {
     // ...
     return [ $route, $parameters ];
}

@alexdodonov
Copy link
Owner

alexdodonov commented Jul 25, 2022

I suppose it is related to middlewares being refactored in 1.5, as it worked fine in 1.4.

I think you are right.

Is the below still correct?

Since v.1.5.0 $parameters are passed in a middleware not like an array, but as a separate paremeters.

It was working like this:

// for example $parameters = ['id' => 1]
$router->registerMiddleware('*', function(string $route, array $parameters = []) {
     // works correct in the v.1.4.x
     return [ $route, $parameters ];
}

And now it is working in this way:

// for the url = /user/1 and pattern /user/[i:id]
$router->registerMiddleware('*', function(string $route, int $id) {
     // works correct in the v.1.5.x
     return [ $route, $id];
}

@Robinjoeh
Copy link
Author

Perfect, did some adjustments to the code.

Works perfectly. Well done! Thanks a lot.

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