Skip to content

Conversation

@ondrej-tuhacek
Copy link
Contributor

No description provided.


// path & query
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
$requestUrl = isset($_SERVER['REQUEST_URI']) ? Strings::replace($_SERVER['REQUEST_URI'], '#^\w+://[^/]+#i') : '/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to make it more readable by splitting it into lines.

$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; $requestUrl = Strings::replace($requestUrl, '#^\w+://[^/]+#i');

The pattern could be optimized by removing pointless case-insensitive flag and avoiding any possible backtracking

$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; $requestUrl = Strings::replace($requestUrl, '#^\w++://[^/]++#');

With removed backtracking, we may probably replace Strings::replace with faster preg_replace

$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; $requestUrl = preg_replace('#^\w++://[^/]++#', '', $requestUrl);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, you're right. I have modified it. Thanks.


// path & query
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
$requestUrl = preg_replace('#^\w++://[^/]++#', '', $requestUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually RFC compliant? What if I send mismatching Host header or use different protocol than used in here? Shouldn't we strip it only if it is a match and throw exception otherwise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See how Symfony handles this. They replace it only if it matches current schema and host. But I haven't seen any specification which would define how this should actually be handled.

@dg dg merged commit dff9775 into nette:master Jun 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants