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

added support for parameters with default null #581

Merged
merged 1 commit into from Apr 19, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Symfony/Component/Routing/Generator/UrlGenerator.php
Expand Up @@ -99,8 +99,11 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $requirements[$token[3]], $tparams[$token[3]]));
}

// %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitely allowed it)
$url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url;
if (isset($tparams[$token[3]])) {
// %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitly allowed it)
$url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url;
}

$optional = false;
}
} elseif ('text' === $token[0]) {
Expand Down
Expand Up @@ -119,7 +119,22 @@ public function testRelativeUrlWithParameter()

$this->assertEquals('/app.php/testing/bar', $url);
}


public function testRelativeUrlWithNullParameter()
{
$this->routeCollection->add('test', new Route('/testing.{format}', array('format' => null)));
$this->generator->setContext(array(
'base_url'=>'/app.php',
'method'=>'GET',
'host'=>'localhost',
'port'=>80,
'is_secure'=>false));

$url = $this->generator->generate('test', array(), false);

$this->assertEquals('/app.php/testing', $url);
}

public function testRelativeUrlWithExtraParameters()
{
$this->routeCollection->add('test', new Route('/testing'));
Expand Down