From c275beecebb96a914616e39ec61a22e4597358ec Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 28 Sep 2018 22:32:19 +0200 Subject: [PATCH 1/2] Allow url without / for overwrite.cli.url Signed-off-by: Daniel Kesselberg --- lib/private/Setup.php | 5 ++--- tests/lib/SetupTest.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index d5ccde6bba..9f5403b831 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -445,11 +445,10 @@ class Setup { if ($webRoot === '') { throw new InvalidArgumentException('overwrite.cli.url is empty'); } - $webRoot = parse_url($webRoot, PHP_URL_PATH); - if ($webRoot === null) { + if (!filter_var($webRoot, FILTER_VALIDATE_URL)) { throw new InvalidArgumentException('invalid value for overwrite.cli.url'); } - $webRoot = rtrim($webRoot, '/'); + $webRoot = rtrim(parse_url($webRoot, PHP_URL_PATH), '/'); } else { $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; } diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index 628f9393c1..68ef0b2913 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -153,14 +153,21 @@ class SetupTest extends \Test\TestCase { } \OC::$CLI = $cliState; - $this->assertEquals($webRoot, $expected); + $this->assertSame($webRoot, $expected); } public function findWebRootProvider(): array { return [ 'https://www.example.com/nextcloud' => ['https://www.example.com/nextcloud', '/nextcloud'], 'https://www.example.com/' => ['https://www.example.com/', ''], - 'https://www.example.com' => ['https://www.example.com', false], + 'https://www.example.com' => ['https://www.example.com', ''], + 'https://nctest13pgsql.lan/nextcloud' => ['https://nctest13pgsql.lan/', ''], + 'https://nctest13pgsql.lan/' => ['https://nctest13pgsql.lan/', ''], + 'https://nctest13pgsql.lan' => ['https://nctest13pgsql.lan', ''], + 'https://192.168.10.10/nc' => ['https://192.168.10.10/nc', '/nc'], + 'https://192.168.10.10/' => ['https://192.168.10.10/', ''], + 'https://192.168.10.10' => ['https://192.168.10.10', ''], + 'invalid' => ['invalid', false], 'empty' => ['', false], ]; } From 9dae927b0c666f8db70732b0ac098b44ed913d92 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Sun, 30 Sep 2018 12:24:38 +0200 Subject: [PATCH 2/2] Add more test cases Signed-off-by: Daniel Kesselberg --- tests/lib/SetupTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index 68ef0b2913..176a5b19f2 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -158,12 +158,15 @@ class SetupTest extends \Test\TestCase { public function findWebRootProvider(): array { return [ + 'https://www.example.com/nextcloud/' => ['https://www.example.com/nextcloud/', '/nextcloud'], 'https://www.example.com/nextcloud' => ['https://www.example.com/nextcloud', '/nextcloud'], 'https://www.example.com/' => ['https://www.example.com/', ''], 'https://www.example.com' => ['https://www.example.com', ''], - 'https://nctest13pgsql.lan/nextcloud' => ['https://nctest13pgsql.lan/', ''], + 'https://nctest13pgsql.lan/test123/' => ['https://nctest13pgsql.lan/test123/', '/test123'], + 'https://nctest13pgsql.lan/test123' => ['https://nctest13pgsql.lan/test123', '/test123'], 'https://nctest13pgsql.lan/' => ['https://nctest13pgsql.lan/', ''], 'https://nctest13pgsql.lan' => ['https://nctest13pgsql.lan', ''], + 'https://192.168.10.10/nc/' => ['https://192.168.10.10/nc/', '/nc'], 'https://192.168.10.10/nc' => ['https://192.168.10.10/nc', '/nc'], 'https://192.168.10.10/' => ['https://192.168.10.10/', ''], 'https://192.168.10.10' => ['https://192.168.10.10', ''],