]> source.dussan.org Git - nextcloud-server.git/commitdiff
added helper function to escape glob pattern
authorBjörn Schießle <schiessle@owncloud.com>
Fri, 5 Jul 2013 12:58:33 +0000 (14:58 +0200)
committerBjörn Schießle <schiessle@owncloud.com>
Fri, 5 Jul 2013 14:03:20 +0000 (16:03 +0200)
Conflicts:

apps/files_encryption/lib/helper.php

apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/helper.php
apps/files_encryption/lib/keymanager.php

index c26119b6c2efb5c5ac071cb50cd96ce0d9b5b42c..b2a17f6bca5e344646a76a8e42354d765f439ed4 100644 (file)
@@ -497,7 +497,7 @@ class Hooks {
 \r
                        // handle share-keys\r
                        $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']);\r
-                       $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath);\r
+                       $escapedPath = Helper::escapeGlobPattern($localKeyPath);\r
                        $matches = glob($escapedPath . '*.shareKey');\r
                        foreach ($matches as $src) {\r
                                $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src));\r
index 31cf48a0393c13459877117daffd9df624ca4b8d..1b9637c1b9af0ce11229a63d7f10892630158392 100755 (executable)
@@ -218,7 +218,6 @@ class Helper {
                exit();
        }
 
-
        /**
         * check requirements for encryption app.
         * @return bool true if requirements are met
@@ -234,3 +233,14 @@ class Helper {
                return (bool) $result;
        }
 }
+
+       /**
+        * @brief glob uses different pattern than regular expressions, escape glob pattern only
+        * @param unescaped path
+        * @return escaped path
+        */
+       public static function escapeGlobPattern($path) {
+               return preg_replace('/(\*|\?|\[)/', '[$1]', $path);
+       }
+}
+
index da2ee380e89bc780cb9b57c37e838dbfcf559d52..b2fd650f18df497064db867f92048bef39bcddbe 100755 (executable)
@@ -488,7 +488,7 @@ class Keymanager {
                        $view->unlink($baseDir . $filePath);
                } else {
                        $localKeyPath = $view->getLocalFile($baseDir . $filePath);
-                       $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath);
+                       $escapedPath = Helper::escapeGlobPattern($localKeyPath);
                        $matches = glob($escapedPath . '*.shareKey');
                        foreach ($matches as $ma) {
                                $result = unlink($ma);
@@ -549,8 +549,8 @@ class Keymanager {
        private static function recursiveDelShareKeys($dir, $userIds) {
                foreach ($userIds as $userId) {
                        $extension = '.' . $userId . '.shareKey';
-                       $escapedDir = preg_replace('/(\*|\?|\[)/', '[$1]', $dir);
-                       $escapedExtension = preg_replace('/(\*|\?|\[)/', '[$1]', $extension);
+                       $escapedDir = Helper::escapeGlobPattern($dir);
+                       $escapedExtension = Helper::escapeGlobPattern($extension);
                        $matches = glob($escapedDir . '/*' . $escapedExtension);
                }
                /** @var $matches array */