[Pkg-owncloud-commits] [owncloud] 09/14: Normalize before processing
David Prévot
taffit at moszumanska.debian.org
Wed Mar 11 15:49:33 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v6.0.7
in repository owncloud.
commit 267341fbeba5d1ef110b50e7cead9b0d26068fc1
Author: Lukas Reschke <lukas at owncloud.com>
Date: Fri Feb 6 15:22:25 2015 +0100
Normalize before processing
---
lib/private/files/filesystem.php | 10 ++++++----
lib/private/files/mapper.php | 2 +-
tests/lib/files/filesystem.php | 22 ++++++++++++++++++++++
tests/lib/files/mapper.php | 11 ++++++++++-
4 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 0aa5f16..7b031cb 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -452,9 +452,10 @@ class Filesystem {
* @return bool
*/
static public function isFileBlacklisted($filename) {
+ $filename = self::normalizePath($filename);
$blacklist = \OC_Config::getValue('blacklisted_files', array('.htaccess'));
$filename = strtolower(basename($filename));
- return (in_array($filename, $blacklist));
+ return in_array($filename, $blacklist);
}
/**
@@ -618,6 +619,10 @@ class Filesystem {
if ($path == '') {
return '/';
}
+
+ //normalize unicode if possible
+ $path = \OC_Util::normalizeUnicode($path);
+
//no windows style slashes
$path = str_replace('\\', '/', $path);
@@ -646,9 +651,6 @@ class Filesystem {
$path = substr($path, 0, -2);
}
- //normalize unicode if possible
- $path = \OC_Util::normalizeUnicode($path);
-
return $path;
}
diff --git a/lib/private/files/mapper.php b/lib/private/files/mapper.php
index 47abd4e..b263394 100644
--- a/lib/private/files/mapper.php
+++ b/lib/private/files/mapper.php
@@ -230,7 +230,7 @@ class Mapper
// trim ending dots (for security reasons and win compatibility)
$text = preg_replace('~\.+$~', '', $text);
- if (empty($text)) {
+ if (empty($text) || \OC\Files\Filesystem::isFileBlacklisted($text)) {
return uniqid();
}
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index b0ed065..6c83afc 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -101,6 +101,28 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
}
}
+ public function isFileBlacklistedData() {
+ return array(
+ array('/etc/foo/bar/foo.txt', false),
+ array('\etc\foo/bar\foo.txt', false),
+ array('.htaccess', true),
+ array('.htaccess/', true),
+ array('.htaccess\\', true),
+ array('/etc/foo\bar/.htaccess\\', true),
+ array('/etc/foo\bar/.htaccess/', true),
+ array('/etc/foo\bar/.htaccess/foo', false),
+ array('//foo//bar/\.htaccess/', true),
+ array('\foo\bar\.HTAccess', true),
+ );
+ }
+
+ /**
+ * @dataProvider isFileBlacklistedData
+ */
+ public function testIsFileBlacklisted($path, $expected) {
+ $this->assertSame($expected, \OC\Files\Filesystem::isFileBlacklisted($path));
+ }
+
public function testNormalizeWindowsPaths() {
$this->assertEquals('/', \OC\Files\Filesystem::normalizePath(''));
$this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\'));
diff --git a/tests/lib/files/mapper.php b/tests/lib/files/mapper.php
index 48ae95b..1b9685b 100644
--- a/tests/lib/files/mapper.php
+++ b/tests/lib/files/mapper.php
@@ -59,6 +59,15 @@ class Mapper extends \PHPUnit_Framework_TestCase {
$this->assertEquals('D:/folder.name.with.peri-ods/te-st-2.t-x-t', $this->mapper->slugifyPath('D:/folder.name.with.peri ods/te st.t x t', 2));
$this->assertEquals('D:/folder.name.with.peri-ods/te-st.t-x-t', $this->mapper->slugifyPath('D:/folder.name.with.peri ods/te st.t x t'));
-
+ // blacklisted files
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath(' D:/.htaccess'));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htaccess '));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath(' D:/.htaccess '));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htaccess'));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htaccess.'));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htAccess'));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htAccess\…\/とa'));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htaccess-'));
+ $this->assertNotEquals('D:/.htaccess', $this->mapper->slugifyPath('D:/.htaあccess'));
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list