Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Symfony/Component/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@ public function getPath()
* This method implements a fluent interface.
*
* @param string $pattern The path pattern
* @param bool $trim whether or not to trim and format the $pattern.
*
* @return Route The current Route instance
*/
public function setPath($pattern)
public function setPath($pattern, $trim = true)
{
// 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;
Copy link
Contributor

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

Copy link
Contributor Author

@ragboyjr ragboyjr May 3, 2016

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)

$this->compiled = null;

return $this;
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,17 @@ public function testSerializedRepresentationKeepsWorking()
$this->assertEquals($route, $unserialized);
$this->assertNotSame($route, $unserialized);
}

/**
* Tests that the setPath trim flag can be changed to allow non-trimming
* of routes.
*/
public function testSetPathTrimFlag()
{
$route = new Route('/');
$path = ' path ';
$route->setPath($path, false);

$this->assertEquals($path, $route->getPath());
}
}