summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-08-14 02:44:45 +0200
committerRobin Appelman <icewind@owncloud.com>2012-08-14 02:44:45 +0200
commit0c8ce0bb32c4a79c248e71533f9fa00b844049fb (patch)
tree94764ed5d50bf2a2e751fa413231f49cfdb24670
parentc31217125293c405941c1b515cb94bdf0a14a35b (diff)
downloadnextcloud-server-0c8ce0bb32c4a79c248e71533f9fa00b844049fb.tar.gz
nextcloud-server-0c8ce0bb32c4a79c248e71533f9fa00b844049fb.zip
some basic path normalization
-rw-r--r--lib/filesystem.php22
-rw-r--r--lib/filesystemview.php5
-rw-r--r--tests/lib/filesystem.php11
3 files changed, 35 insertions, 3 deletions
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 5af6e0aa54c..221345332b0 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -494,6 +494,28 @@ class OC_Filesystem{
}
OC_Connector_Sabre_Node::removeETagPropertyForPath($path);
}
+
+ public static function normalizePath($path){
+ //no windows style slashes
+ $path=str_replace('\\','/',$path);
+ //add leading slash
+ if($path[0]!=='/'){
+ $path='/'.$path;
+ }
+ //remove trainling slash
+ if(substr($path,-1,1)==='/'){
+ $path=substr($path,0,-1);
+ }
+ //remove duplicate slashes
+ while(strpos($path,'//')!==false){
+ $path=str_replace('//','/',$path);
+ }
+ //normalize unicode if possible
+ if(class_exists('Normalizer')){
+ $path=Normalizer::normalize($path);
+ }
+ return $path;
+ }
}
OC_Hook::connect('OC_Filesystem','post_write', 'OC_Filesystem','removeETagHook');
OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook');
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index faf3f0bd4cc..17d09a07001 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -54,10 +54,9 @@ class OC_FilesystemView {
if($path[0]!=='/'){
$path='/'.$path;
}
- return $this->fakeRoot.$path;
+ return OC_Filesystem::normalizePath($this->fakeRoot.$path);
}
-
-
+
/**
* change the root to a fake toor
* @param string fakeRoot
diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
index 3e28d8c06e5..e041255ec91 100644
--- a/tests/lib/filesystem.php
+++ b/tests/lib/filesystem.php
@@ -59,6 +59,17 @@ class Test_Filesystem extends UnitTestCase{
$this->assertEqual('/',OC_Filesystem::getMountPoint('/some'));
$this->assertEqual('folder',OC_Filesystem::getInternalPath('/some/folder'));
}
+
+ public function testNormalize(){
+ $this->assertEqual('/path',OC_Filesystem::normalizePath('/path/'));
+ $this->assertEqual('/path',OC_Filesystem::normalizePath('path'));
+ $this->assertEqual('/path',OC_Filesystem::normalizePath('\path'));
+ $this->assertEqual('/foo/bar',OC_Filesystem::normalizePath('/foo//bar/'));
+ $this->assertEqual('/foo/bar',OC_Filesystem::normalizePath('/foo////bar'));
+ if(class_exists('Normalizer')){
+ $this->assertEqual("/foo/bar\xC3\xBC",OC_Filesystem::normalizePath("/foo/baru\xCC\x88"));
+ }
+ }
}
?> \ No newline at end of file