From 76c63a576089edcd553244f02d8c3f6c28038fd2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 31 Mar 2014 17:00:32 +0200 Subject: [PATCH] Fix uploading files containing a # in the path for webdav --- apps/files_external/lib/webdav.php | 2 +- tests/lib/files/storage/storage.php | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 279ae716935..f5010f92208 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -267,7 +267,7 @@ class DAV extends \OC\Files\Storage\Common { $curl = curl_init(); curl_setopt($curl, CURLOPT_USERPWD, $this->user . ':' . $this->password); - curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . str_replace(' ', '%20', $target)); + curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . $this->encodePath($target)); curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); curl_setopt($curl, CURLOPT_INFILE, $source); // file pointer curl_setopt($curl, CURLOPT_INFILESIZE, filesize($path)); diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index f3bfba3feb8..e4d9e93ca97 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -299,7 +299,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->instance->file_exists('folder')); } - public function hashProvider(){ + public function hashProvider() { return array( array('Foobar', 'md5'), array('Foobar', 'sha1'), @@ -315,4 +315,23 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt')); $this->assertEquals(hash($type, $data, true), $this->instance->hash($type, 'hash.txt', true)); } + + public function testHashInFileName() { + $this->instance->file_put_contents('#test.txt', 'data'); + $this->assertEquals('data', $this->instance->file_get_contents('#test.txt')); + + $this->instance->mkdir('#foo'); + $this->instance->file_put_contents('#foo/test.txt', 'data'); + $this->assertEquals('data', $this->instance->file_get_contents('#foo/test.txt')); + + $dh = $this->instance->opendir('#foo'); + $content = array(); + while ($file = readdir($dh)) { + if ($file != '.' and $file != '..') { + $content[] = $file; + } + } + + $this->assertEquals(array('test.txt'), $content); + } } -- 2.39.5