-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Added trim flag to Route::setPath #18702
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
Conversation
558afe6
to
f8d1b6e
Compare
Added a trim flag to Route::setPath in order to allow paths to be set as is without any trimming to sanitize the input Signed-off-by: RJ Garcia <[email protected]>
f8d1b6e
to
e1fc962
Compare
Hmm, something in the DependencyInjection component is making travis fail on hhvm. |
@Ener-Getick, @stof, @GromNaN, Oh, you know, I just though of another solution that could actually work for everyone. What if we added a new protected method in the Route like this public function setPath($pattern)
{
// A pattern must start with a slash and must not have multiple slashes at the beginning because the
// generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
return $this->doSetPath('/'.ltrim(trim($pattern), '/'));
}
protected function doSetPath($pattern)
{
$this->path = $pattern;
$this->compiled = null;
return $this;
} or, instead of protected, we could always make Either way, this wouldn't break BC, and is a cleaner solution that prevents "monkey patching" |
Can you describe your use case where you would like to have trimming disabled? |
Basically, there is an issue with mounted/prefixed routes. where if the prefix was |
{ | ||
// A pattern must start with a slash and must not have multiple slashes at the beginning because the | ||
// generated path for this route would be confused with a network path, e.g. '//domain.com/path'. | ||
$this->path = '/'.ltrim(trim($pattern), '/'); | ||
$this->path = $trim ? '/'.ltrim(trim($pattern), '/') : $pattern; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the double slash removal must be kept as described in the comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tobion Well, what would you think about doing this instead: #18702 (comment)
It took me some time to understand the issue so in case it helps here is an illustration with a routing file: // routing.yml
sub_routing:
resource: sub_routing.yml
prefix: /foo // sub_routing.yml
my_route:
path: ''
// you would expect to be able to access /foo here
// but you can only access /foo/ as paths are always
// prefixed with a / |
@Ener-Getick, that is precisely it. I wasn't accustomed to the Syfmony configuration for this because I was referring to Silex, but, yes it's the same exact issue. |
Another solution could be to detect empty paths and to not format them. |
@Ener-Getick, that would work for me as well, but that would be also be a BC break, unless we considered this a bug in the way it handles empty urls. And it could potentially break someone's code if they were expecting that But if that's not a documented feature, then we might be able to get away with it. |
This seems related to #12141 too. |
I'm closing here as what @GuilhemN describes is exactly how this should work. When mounting a resource, like on a filesystem, the prefix is a directory. |
@fabpot sounds good, thanks. |
silexphp/Silex#149
Added a trim flag to the Route setPath. This replaces #18701
Signed-off-by: RJ Garcia [email protected]