From 753eaf66693f17e8a0bbc16b357c71cb7ee96f00 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 17 Apr 2018 20:01:43 +0300 Subject: [PATCH] Strip trailing slash before concatenation. Add more testcases --- lib/private/App/AppManager.php | 4 ++- tests/lib/App/ManagerTest.php | 56 +++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index d322a26ac1da..26dbe696716a 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -531,7 +531,9 @@ public function getAppWebPath($appId) { $appRoot['url'] = substr($appRoot['url'], 3); $ocWebRoot = dirname($ocWebRoot); } - return $ocWebRoot . '/' . ltrim($appRoot['url'], '/'); + $trimmedOcWebRoot = rtrim($ocWebRoot, '/'); + $trimmedAppRoot = ltrim($appRoot['url'], '/'); + return "$trimmedOcWebRoot/$trimmedAppRoot"; } return false; } diff --git a/tests/lib/App/ManagerTest.php b/tests/lib/App/ManagerTest.php index 6c3b892d2b56..b05c06dc9619 100644 --- a/tests/lib/App/ManagerTest.php +++ b/tests/lib/App/ManagerTest.php @@ -530,7 +530,15 @@ public function testPathIsNotCachedForNotFoundApp() { $this->assertFalse($appPath); } - public function testAppWebRootAboveOcWebroot() { + /** + * @dataProvider appAboveWebRootDataProvider + * + * @param string $ocWebRoot + * @param string[] $appData + * @param string $expectedAppWebPath + */ + public function testAppWebRootAboveOcWebRoot($ocWebRoot, $appData, + $expectedAppWebPath) { $appId = 'notexistingapp'; $appManager = $this->getMockBuilder(AppManager::class) @@ -540,17 +548,51 @@ public function testAppWebRootAboveOcWebroot() { $appManager->expects($this->any()) ->method('getOcWebRoot') - ->willReturn('some/host/path'); + ->willReturn($ocWebRoot); $appManager->expects($this->any()) ->method('findAppInDirectories') ->with($appId) - ->willReturn([ - 'path' => '/not/essential', - 'url' => '../../relative', - ]); + ->willReturn($appData); $appWebPath = $appManager->getAppWebPath($appId); - $this->assertEquals('some/relative', $appWebPath); + $this->assertEquals($expectedAppWebPath, $appWebPath); + } + + public function appAboveWebRootDataProvider(){ + return [ + [ + '/some/host/path', + [ + 'path' => '/not/essential', + 'url' => '../../relative', + ], + '/some/relative' + ], + [ + '/some/host/path', + [ + 'path' => '/not/essential', + 'url' => '../relative', + ], + '/some/host/relative' + ], + [ + '/some/hostPath', + [ + 'path' => '/not/essential', + 'url' => '../relative', + ], + '/some/relative' + ], + [ + '/someHostPath', + [ + 'path' => '/not/essential', + 'url' => '../relative', + ], + '/relative' + ], + ]; } }