Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,20 @@ public function getRequestUri() {
$uri = isset($this->server['REQUEST_URI']) ? $this->server['REQUEST_URI'] : '';
if($this->config->getSystemValue('overwritewebroot') !== '' && $this->isOverwriteCondition()) {
$uri = $this->getScriptName() . substr($uri, strlen($this->server['SCRIPT_NAME']));
} else {
$components = parse_url($uri);
if ($components === false) {
// due to https://bugs.php.net/bug.php?id=70942 we have to add a
// fake schema and host to successfully extract path, query and fragment
$components = parse_url("http://localhost$uri");
}
$uri = $components['path'];
if (isset($components['query'])) {
$uri .= '?'.$components['query'];
}
if (isset($components['fragment'])) {
$uri .= '#'.$components['fragment'];
}
}
return $uri;
}
Expand Down
24 changes: 20 additions & 4 deletions tests/lib/AppFramework/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
use OCP\IRequest;
use OCP\Security\ISecureRandom;
use OCP\IConfig;
use Test\TestCase;

/**
* Class RequestTest
*
* @package OC\AppFramework\Http
*/
class RequestTest extends \Test\TestCase {
class RequestTest extends TestCase {
/** @var string */
protected $stream = 'fakeinput://data';
/** @var ISecureRandom | \PHPUnit_Framework_MockObject_MockObject */
Expand Down Expand Up @@ -1337,7 +1338,22 @@ public function pathInfoProvider() {
];
}

public function testGetRequestUriWithoutOverwrite() {
public function providesUri() {
return[
['/test.php', '/test.php'],
['/remote.php/dav/files/user0/test_folder:5', '/remote.php/dav/files/user0/test_folder:5'],
['/remote.php/dav/files/admin/welcome.txt', 'http://localhost:8080/remote.php/dav/files/admin/welcome.txt'],
['/path?arg=value#anchor', 'http://username:password@hostname:9090/path?arg=value#anchor'],
['/path:5?arg=value#anchor', 'http://username:password@hostname:9090/path:5?arg=value#anchor'],
['', ''],
['/test.php', '/test.php'],
];
}

/**
* @dataProvider providesUri
*/
public function testGetRequestUriWithoutOverwrite($expectedUri, $requestUri) {
$this->config
->expects($this->once())
->method('getSystemValue')
Expand All @@ -1347,7 +1363,7 @@ public function testGetRequestUriWithoutOverwrite() {
$request = new Request(
[
'server' => [
'REQUEST_URI' => '/test.php'
'REQUEST_URI' => $requestUri
]
],
$this->secureRandom,
Expand All @@ -1356,7 +1372,7 @@ public function testGetRequestUriWithoutOverwrite() {
$this->stream
);

$this->assertSame('/test.php', $request->getRequestUri());
$this->assertSame($expectedUri, $request->getRequestUri());
}

public function providesGetRequestUriWithOverwriteData() {
Expand Down