Allow empty strings in getAbsoluteURL

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/12553/head
Joas Schilling 6 years ago
parent 2b18b9ae96
commit b8fcf6e9b3
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
  1. 4
      lib/private/URLGenerator.php
  2. 2
      tests/lib/UrlGeneratorTest.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));
}

@ -145,6 +145,8 @@ class UrlGeneratorTest extends \Test\TestCase {
public function provideSubDirURLs() {
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'],

Loading…
Cancel
Save