]> source.dussan.org Git - nextcloud-server.git/commitdiff
Removing trailing dot in path that samba doesn't seem to like
authorVincent Petry <pvince81@owncloud.com>
Thu, 14 Nov 2013 15:52:00 +0000 (16:52 +0100)
committerVincent Petry <pvince81@owncloud.com>
Tue, 19 Nov 2013 14:05:11 +0000 (15:05 +0100)
Fixes #5778
Added unit test for getId() and constructUrl()

apps/files_external/lib/smb.php
apps/files_external/tests/smbfunctions.php [new file with mode: 0644]

index ecd4dae04849a19dccd316bb0f11d0e1f9411b78..c464fa9107a79e59ff8b30b26dedc11aec9cc99e 100644 (file)
@@ -47,8 +47,13 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
 
        public function constructUrl($path) {
                if (substr($path, -1)=='/') {
-                       $path=substr($path, 0, -1);
+                       $path = substr($path, 0, -1);
                }
+               if (substr($path, 0, 1)=='/') {
+                       $path = substr($path, 1);
+               }
+               // remove trailing dots which some versions of samba don't seem to like
+               $path = rtrim($path, '.');
                $path = urlencode($path);
                $user = urlencode($this->user);
                $pass = urlencode($this->password);
diff --git a/apps/files_external/tests/smbfunctions.php b/apps/files_external/tests/smbfunctions.php
new file mode 100644 (file)
index 0000000..749906d
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright (c) 2013 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Storage;
+
+class SMBFunctions extends \PHPUnit_Framework_TestCase {
+
+       public function setUp() {
+               $id = uniqid();
+               // dummy config
+               $this->config = array(
+                       'run'=>false,
+                       'user'=>'test',
+                       'password'=>'testpassword',
+                       'host'=>'smbhost',
+                       'share'=>'/sharename',
+                       'root'=>'/rootdir/',
+               );
+
+               $this->instance = new \OC\Files\Storage\SMB($this->config);
+       }
+
+       public function tearDown() {
+       }
+
+       public function testGetId() {
+               $this->assertEquals('smb::test@smbhost//sharename//rootdir/', $this->instance->getId());
+       }
+
+       public function testConstructUrl() {
+               $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc", $this->instance->constructUrl('/abc'));
+               $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc", $this->instance->constructUrl('/abc/'));
+               $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc%2F", $this->instance->constructUrl('/abc/.'));
+               $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc%2Fdef", $this->instance->constructUrl('/abc/def'));
+       }
+}