Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Include querystring parameters when issuing a redirect from Redirecta…

…bleUrlMatcher
  • Loading branch information...
commit 090347771184f93324efe28312b3036942beca7e 1 parent 59e7dbd
@lmcnearney lmcnearney authored committed
View
5 src/Silex/Application.php
@@ -125,6 +125,11 @@ public function __construct(array $values = array())
});
$this['url_matcher'] = $this->share(function () use ($app) {
+ // Inject the query string into the RequestContext for Symfony versions <= 2.2
+ if ($app['request']->server->get('QUERY_STRING') !== '' && !method_exists($app['request_context'], 'getQueryString')) {
+ $app['request_context']->setParameter('QUERY_STRING', $app['request']->server->get('QUERY_STRING'));
+ }
+
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
View
10 src/Silex/RedirectableUrlMatcher.php
@@ -29,6 +29,16 @@ public function redirect($path, $route, $scheme = null)
{
$url = $this->context->getBaseUrl().$path;
+ // Query string support was added to RequestContext in 2.3
+ // Fall back to parameter injected by url_matcher closure for earlier versions
+ $query = method_exists($this->context, 'getQueryString')
+ ? $this->context->getQueryString()
+ : $this->context->getParameter('QUERY_STRING') ?: '';
+
+ if ($query !== '') {
+ $url .= '?'.$query;
+ }
+
if ($this->context->getHost()) {
if ($scheme) {
$port = '';
View
14 tests/Silex/Tests/RouterTest.php
@@ -207,6 +207,20 @@ public function testRequireHttpsRedirect()
$this->assertTrue($response->isRedirect('https://example.com/secured'));
}
+ public function testRequireHttpsRedirectIncludesQueryString()
+ {
+ $app = new Application();
+
+ $app->match('/secured', function () {
+ return 'secured content';
+ })
+ ->requireHttps();
+
+ $request = Request::create('http://example.com/secured?query=string');
+ $response = $app->handle($request);
+ $this->assertTrue($response->isRedirect('https://example.com/secured?query=string'));
+ }
+
public function testClassNameControllerSyntax()
{
$app = new Application();
Please sign in to comment.
Something went wrong with that request. Please try again.