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
6 changes: 3 additions & 3 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function index($dir = '', $view = '', $fileid = null) {
return $item1['order'] - $item2['order'];
});
$nav->assign('navigationItems', $navItems);
$nav->assign('webdavUrl', $this->urlGenerator->getAbsoluteUrl($this->urlGenerator->linkTo('', 'remote.php') . '/dav/files/' . $user . '/'));
$nav->assign('webdavUrl', $this->urlGenerator->getAbsoluteUrl($this->urlGenerator->linkTo('', 'remote.php') . '/dav/files/' . rawurlencode($user) . '/'));

$contentItems = [];

Expand Down Expand Up @@ -307,8 +307,8 @@ public function showFile($fileId) {
}
$response = new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
if ($isFilesView) {
$webdavUrl = $this->urlGenerator->linkTo('', 'remote.php') . '/dav/files/' . $uid . '/';
$webdavUrl .= ltrim($baseFolder->getRelativePath($file->getPath()), '/');
$webdavUrl = $this->urlGenerator->linkTo('', 'remote.php') . '/dav/files/' . rawurlencode($uid) . '/';
$webdavUrl .= \OCP\Util::encodePath(ltrim($baseFolder->getRelativePath($file->getPath()), '/'));
$response->addHeader('Webdav-Location', $webdavUrl);
}
return $response;
Expand Down
48 changes: 24 additions & 24 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function setUp() {
$this->user = $this->createMock('\OCP\IUser');
$this->user->expects($this->any())
->method('getUID')
->will($this->returnValue('testuser1'));
->will($this->returnValue('test@#?%test'));
$this->userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
Expand Down Expand Up @@ -189,8 +189,8 @@ public function testIndexWithRegularBrowser() {
->with('', 'remote.php')
->willReturn('/owncloud/remote.php');
$this->urlGenerator->method('getAbsoluteUrl')
->with('/owncloud/remote.php/dav/files/' . $this->user->getUID() . '/')
->willReturn('http://example.org/owncloud/remote.php/dav/files/' . $this->user->getUID() . '/');
->with('/owncloud/remote.php/dav/files/test%40%23%3F%25test/')
->willReturn('http://example.org/owncloud/remote.php/dav/files/test%40%23%3F%25test/');

$nav = new Template('files', 'appnavigation');
$nav->assign('navigationItems', [
Expand Down Expand Up @@ -258,7 +258,7 @@ public function testIndexWithRegularBrowser() {
'icon' => '',
],
]);
$nav->assign('webdavUrl', 'http://example.org/owncloud/remote.php/dav/files/' . $this->user->getUID() . '/');
$nav->assign('webdavUrl', 'http://example.org/owncloud/remote.php/dav/files/test%40%23%3F%25test/');

$expected = new Http\TemplateResponse(
'files',
Expand Down Expand Up @@ -329,13 +329,13 @@ public function testShowFileRouteWithFolder($useShowFile) {
$node = $this->createMock('\OCP\Files\Folder');
$node->expects($this->any())
->method('getPath')
->will($this->returnValue('/testuser1/files/test/sub'));
->will($this->returnValue('/test@#?%test/files/to sp@ce/a@b#?%'));

$baseFolder = $this->createMock('\OCP\Files\Folder');

$this->rootFolder->expects($this->once())
->method('get')
->with('testuser1/files/')
->with('test@#?%test/files/')
->will($this->returnValue($baseFolder));

$baseFolder->expects($this->any())
Expand All @@ -344,17 +344,17 @@ public function testShowFileRouteWithFolder($useShowFile) {
->will($this->returnValue([$node]));
$baseFolder->expects($this->any())
->method('getRelativePath')
->with('/testuser1/files/test/sub')
->will($this->returnValue('/test/sub'));
->with('/test@#?%test/files/to sp@ce/a@b#?%')
->will($this->returnValue('/to sp@ce/a@b#?%'));

$this->urlGenerator
->expects($this->once())
->method('linkToRoute')
->with('files.view.index', ['dir' => '/test/sub'])
->will($this->returnValue('/owncloud/index.php/apps/files/?dir=/test/sub'));
->with('files.view.index', ['dir' => '/to sp@ce/a@b#?%'])
->will($this->returnValue('/owncloud/index.php/apps/files/?dir=/to%20sp%40ce/a%40b%23%3F%25'));

$expected = new Http\RedirectResponse('/owncloud/index.php/apps/files/?dir=/test/sub');
$expected->addHeader('Webdav-Location', '/owncloud/remote.php/dav/files/testuser1/test/sub');
$expected = new Http\RedirectResponse('/owncloud/index.php/apps/files/?dir=/to%20sp%40ce/a%40b%23%3F%25');
$expected->addHeader('Webdav-Location', '/owncloud/remote.php/dav/files/test%40%23%3F%25test/to%20sp%40ce/a%40b%23%3F%25');
if ($useShowFile) {
$this->assertEquals($expected, $this->viewController->showFile(123));
} else {
Expand All @@ -369,13 +369,13 @@ public function testShowFileRouteWithFile($useShowFile) {
$parentNode = $this->createMock('\OCP\Files\Folder');
$parentNode->expects($this->any())
->method('getPath')
->will($this->returnValue('testuser1/files/test'));
->will($this->returnValue('test@#?%test/files/test'));

$baseFolder = $this->createMock('\OCP\Files\Folder');

$this->rootFolder->expects($this->once())
->method('get')
->with('testuser1/files/')
->with('test@#?%test/files/')
->will($this->returnValue($baseFolder));

$node = $this->createMock('\OCP\Files\File');
Expand All @@ -387,7 +387,7 @@ public function testShowFileRouteWithFile($useShowFile) {
->will($this->returnValue('somefile.txt'));
$node->expects($this->any())
->method('getPath')
->will($this->returnValue('testuser1/files/test/somefile.txt'));
->will($this->returnValue('test@#?%test/files/test/somefile.txt'));

$baseFolder->expects($this->any())
->method('getById')
Expand All @@ -396,8 +396,8 @@ public function testShowFileRouteWithFile($useShowFile) {
$baseFolder->expects($this->any())
->method('getRelativePath')
->will($this->returnValueMap([
['testuser1/files/test', '/test'],
['testuser1/files/test/somefile.txt', '/test/somefile.txt'],
['test@#?%test/files/test', '/test'],
['test@#?%test/files/test/somefile.txt', '/test/somefile.txt'],
]));

$this->urlGenerator
Expand All @@ -407,7 +407,7 @@ public function testShowFileRouteWithFile($useShowFile) {
->will($this->returnValue('/owncloud/index.php/apps/files/?dir=/test&scrollto=somefile.txt'));

$expected = new Http\RedirectResponse('/owncloud/index.php/apps/files/?dir=/test&scrollto=somefile.txt');
$expected->addHeader('Webdav-Location', '/owncloud/remote.php/dav/files/testuser1/test/somefile.txt');
$expected->addHeader('Webdav-Location', '/owncloud/remote.php/dav/files/test%40%23%3F%25test/test/somefile.txt');
if ($useShowFile) {
$this->assertEquals($expected, $this->viewController->showFile(123));
} else {
Expand All @@ -422,7 +422,7 @@ public function testShowFileRouteWithInvalidFileId($useShowFile) {
$baseFolder = $this->createMock('\OCP\Files\Folder');
$this->rootFolder->expects($this->once())
->method('get')
->with('testuser1/files/')
->with('test@#?%test/files/')
->will($this->returnValue($baseFolder));

$baseFolder->expects($this->at(0))
Expand All @@ -447,7 +447,7 @@ public function testShowFileRouteWithInvalidFileIdLoggedIn() {
$baseFolder = $this->createMock('\OCP\Files\Folder');
$this->rootFolder->expects($this->once())
->method('get')
->with('testuser1/files/')
->with('test@#?%test/files/')
->will($this->returnValue($baseFolder));

$baseFolder->expects($this->at(0))
Expand Down Expand Up @@ -481,19 +481,19 @@ public function testShowFileRouteWithTrashedFile($useShowFile) {
$parentNode = $this->createMock('\OCP\Files\Folder');
$parentNode->expects($this->once())
->method('getPath')
->will($this->returnValue('testuser1/files_trashbin/files/test.d1462861890/sub'));
->will($this->returnValue('test@#?%test/files_trashbin/files/test.d1462861890/sub'));

$baseFolderFiles = $this->createMock('\OCP\Files\Folder');
$baseFolderTrash = $this->createMock('\OCP\Files\Folder');

$this->rootFolder->expects($this->at(0))
->method('get')
->with('testuser1/files/')
->with('test@#?%test/files/')
->will($this->returnValue($baseFolderFiles));
//The index is pointing to 2, because nodeExists internally calls get method.
$this->rootFolder->expects($this->at(2))
->method('get')
->with('testuser1/files_trashbin/files/')
->with('test@#?%test/files_trashbin/files/')
->will($this->returnValue($baseFolderTrash));

$baseFolderFiles->expects($this->once())
Expand All @@ -515,7 +515,7 @@ public function testShowFileRouteWithTrashedFile($useShowFile) {
->will($this->returnValue([$node]));
$baseFolderTrash->expects($this->at(1))
->method('getRelativePath')
->with('testuser1/files_trashbin/files/test.d1462861890/sub')
->with('test@#?%test/files_trashbin/files/test.d1462861890/sub')
->will($this->returnValue('/test.d1462861890/sub'));

$this->urlGenerator
Expand Down