Skip to content

Commit

Permalink
Use rawurldecode on the REQUST_URI instead of changing the SCRIPT_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBengalen committed Oct 12, 2016
1 parent ee3f068 commit df1591c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Slim/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ public static function createFromEnvironment(Environment $env)
}

// Path
$envScriptName = str_replace(' ', '%20', $env->get('SCRIPT_NAME'));
$requestScriptName = parse_url($envScriptName, PHP_URL_PATH);
$requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
$requestScriptDir = dirname($requestScriptName);

// parse_url() requires a full URL. As we don't extract the domain name or scheme,
// we use a stand-in.
$requestUri = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_PATH);
$requestUri = rawurldecode($requestUri);

$basePath = '';
$virtualPath = $requestUri;
Expand Down
8 changes: 4 additions & 4 deletions tests/Http/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,15 @@ public function testCreateEnvironmentWithBasePath()
public function testCreateEnvironmentWithBasePathContainingSpace()
{
$environment = Environment::mock([
'SCRIPT_NAME' => '/foo bar/index.php',
'REQUEST_URI' => '/foo%20bar/baz',
'SCRIPT_NAME' => "/f'oo bar/index.php",
'REQUEST_URI' => "/f'oo%20bar/baz",
]);
$uri = Uri::createFromEnvironment($environment);

$this->assertEquals('/foo%20bar', $uri->getBasePath());
$this->assertEquals("/f%27oo%20bar", $uri->getBasePath());
$this->assertEquals('baz', $uri->getPath());

$this->assertEquals('http://localhost/foo%20bar/baz', (string) $uri);
$this->assertEquals('http://localhost/f%27oo%20bar/baz', (string) $uri);
}

public function testGetBaseUrl()
Expand Down

0 comments on commit df1591c

Please sign in to comment.