summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-22 10:26:23 +0100
committerGitHub <noreply@github.com>2018-11-22 10:26:23 +0100
commitede53e06c1cdc2744ecb16641210862398adb961 (patch)
tree7d514e25bd235f5b90a5eb2484a1ad8a87bd752d
parent2e68b73e5ebb34d8200b06554b8ec573eaf42378 (diff)
parentb8fcf6e9b3d492d19bbbdcd144428fef9bbf2324 (diff)
downloadnextcloud-server-ede53e06c1cdc2744ecb16641210862398adb961.tar.gz
nextcloud-server-ede53e06c1cdc2744ecb16641210862398adb961.zip
Merge pull request #12553 from nextcloud/bugfix/noid/allow-empty-string-in-getAbsoluteURL
Allow empty string in get absolute url
-rw-r--r--lib/private/URLGenerator.php4
-rw-r--r--tests/lib/UrlGeneratorTest.php64
2 files changed, 34 insertions, 34 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index f4a83138e4c..167690f3a6e 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -237,13 +237,13 @@ class URLGenerator implements IURLGenerator {
* @return string the absolute version of the url
*/
public function getAbsoluteURL(string $url): string {
- $separator = $url[0] === '/' ? '' : '/';
+ $separator = strpos($url, '/') === 0 ? '' : '/';
if (\OC::$CLI && !\defined('PHPUNIT_RUN')) {
return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
}
// The ownCloud web root can already be prepended.
- if(substr($url, 0, \strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) {
+ if(\OC::$WEBROOT !== '' && strpos($url, \OC::$WEBROOT) === 0) {
$url = substr($url, \strlen(\OC::$WEBROOT));
}
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 0e50f4d92ec..9a8e588a229 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -14,8 +14,6 @@ use OCP\IURLGenerator;
/**
* Class UrlGeneratorTest
- *
- * @group DB
*/
class UrlGeneratorTest extends \Test\TestCase {
@@ -74,7 +72,7 @@ class UrlGeneratorTest extends \Test\TestCase {
* @dataProvider provideSubDirAppUrlParts
*/
public function testLinkToSubDir($app, $file, $args, $expectedResult) {
- \OC::$WEBROOT = '/owncloud';
+ \OC::$WEBROOT = '/nextcloud';
$result = $this->urlGenerator->linkTo($app, $file, $args);
$this->assertEquals($expectedResult, $result);
}
@@ -84,32 +82,32 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
public function testLinkToRouteAbsolute($route, $expected) {
$this->mockBaseUrl();
- \OC::$WEBROOT = '/owncloud';
+ \OC::$WEBROOT = '/nextcloud';
$result = $this->urlGenerator->linkToRouteAbsolute($route);
$this->assertEquals($expected, $result);
}
public function provideRoutes() {
- return array(
- array('files_ajax_list', 'http://localhost/owncloud/index.php/apps/files/ajax/list.php'),
- array('core.Preview.getPreview', 'http://localhost/owncloud/index.php/core/preview.png'),
- );
+ return [
+ ['files_ajax_list', 'http://localhost/nextcloud/index.php/apps/files/ajax/list.php'],
+ ['core.Preview.getPreview', 'http://localhost/nextcloud/index.php/core/preview.png'],
+ ];
}
public function provideDocRootAppUrlParts() {
- return array(
- array('files', 'ajax/list.php', array(), '/index.php/apps/files/ajax/list.php'),
- array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'),
- array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php?trut=trat&dut=dat'),
- );
+ return [
+ ['files', 'ajax/list.php', [], '/index.php/apps/files/ajax/list.php'],
+ ['files', 'ajax/list.php', ['trut' => 'trat', 'dut' => 'dat'], '/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'],
+ ['', 'index.php', ['trut' => 'trat', 'dut' => 'dat'], '/index.php?trut=trat&dut=dat'],
+ ];
}
public function provideSubDirAppUrlParts() {
- return array(
- array('files', 'ajax/list.php', array(), '/owncloud/index.php/apps/files/ajax/list.php'),
- array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'),
- array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php?trut=trat&dut=dat'),
- );
+ return [
+ ['files', 'ajax/list.php', [], '/nextcloud/index.php/apps/files/ajax/list.php'],
+ ['files', 'ajax/list.php', ['trut' => 'trat', 'dut' => 'dat'], '/nextcloud/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'],
+ ['', 'index.php', ['trut' => 'trat', 'dut' => 'dat'], '/nextcloud/index.php?trut=trat&dut=dat'],
+ ];
}
/**
@@ -131,34 +129,36 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
function testGetAbsoluteURLSubDir($url, $expectedResult) {
$this->mockBaseUrl();
- \OC::$WEBROOT = '/owncloud';
+ \OC::$WEBROOT = '/nextcloud';
$result = $this->urlGenerator->getAbsoluteURL($url);
$this->assertEquals($expectedResult, $result);
}
public function provideDocRootURLs() {
- return array(
- array("index.php", "http://localhost/index.php"),
- array("/index.php", "http://localhost/index.php"),
- array("/apps/index.php", "http://localhost/apps/index.php"),
- array("apps/index.php", "http://localhost/apps/index.php"),
- );
+ return [
+ ['index.php', 'http://localhost/index.php'],
+ ['/index.php', 'http://localhost/index.php'],
+ ['/apps/index.php', 'http://localhost/apps/index.php'],
+ ['apps/index.php', 'http://localhost/apps/index.php'],
+ ];
}
public function provideSubDirURLs() {
- return array(
- array("index.php", "http://localhost/owncloud/index.php"),
- array("/index.php", "http://localhost/owncloud/index.php"),
- array("/apps/index.php", "http://localhost/owncloud/apps/index.php"),
- array("apps/index.php", "http://localhost/owncloud/apps/index.php"),
- );
+ return [
+ ['', 'http://localhost/nextcloud/'],
+ ['/', 'http://localhost/nextcloud/'],
+ ['index.php', 'http://localhost/nextcloud/index.php'],
+ ['/index.php', 'http://localhost/nextcloud/index.php'],
+ ['/apps/index.php', 'http://localhost/nextcloud/apps/index.php'],
+ ['apps/index.php', 'http://localhost/nextcloud/apps/index.php'],
+ ];
}
public function testGetBaseUrl() {
$this->mockBaseUrl();
\OC::$WEBROOT = '/nextcloud';
$actual = $this->urlGenerator->getBaseUrl();
- $expected = "http://localhost/nextcloud";
+ $expected = 'http://localhost/nextcloud';
$this->assertEquals($expected, $actual);
}