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

Unescape vars #219

Open
ondrejmirtes opened this issue Sep 17, 2020 · 2 comments
Open

Unescape vars #219

ondrejmirtes opened this issue Sep 17, 2020 · 2 comments

Comments

@ondrejmirtes
Copy link

I have a dispatcher like this:

\FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r): void {
	$r->addRoute('GET', '/license/{package}', $this->licenseHandler);
});

When I visit a URL that looks like this:

/license/clue%2Fndjson-react

I'd expect to receive clue/ndjson-react in $vars['package'] here:

$routeInfo = $this->getDispatcher()->dispatch($request->getMethod(), $request->getUri()->getPath());
$vars = $routeInfo[2];

But instead I receive /license/clue%2Fndjson-react, leaving the unescaping to the handler.

@nikic
Copy link
Owner

nikic commented Sep 17, 2020

The expectation is that dispatch() receives an already decoded URI. The example in https://github.com/nikic/FastRoute#usage uses rawurldecode() to that effect.

@ondrejmirtes
Copy link
Author

The problem with that is that it's not lossless.

Consider this route:

/{foo}/{bar}. Having /one%2Ftwo/three%2Ffour would yield foo being one/two and bar being three/four. But after rawurldecode, it becomes /one/two/three/four, being unable to extract the parameters in a deterministic way.

I know this is an edge case but they usually show wrong abstractions :) Feel free to close this as this is easily solvable in the handler, I'm just used to different behaviour from MVC frameworks...

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