some basic path normalization

remotes/origin/stable45
Robin Appelman 12 years ago
parent c312171252
commit 0c8ce0bb32
  1. 22
      lib/filesystem.php
  2. 5
      lib/filesystemview.php
  3. 11
      tests/lib/filesystem.php

@ -494,6 +494,28 @@ class OC_Filesystem{
} }
OC_Connector_Sabre_Node::removeETagPropertyForPath($path); 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_write', 'OC_Filesystem','removeETagHook');
OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook'); OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook');

@ -54,10 +54,9 @@ class OC_FilesystemView {
if($path[0]!=='/'){ if($path[0]!=='/'){
$path='/'.$path; $path='/'.$path;
} }
return $this->fakeRoot.$path; return OC_Filesystem::normalizePath($this->fakeRoot.$path);
} }
/** /**
* change the root to a fake toor * change the root to a fake toor
* @param string fakeRoot * @param string fakeRoot

@ -59,6 +59,17 @@ class Test_Filesystem extends UnitTestCase{
$this->assertEqual('/',OC_Filesystem::getMountPoint('/some')); $this->assertEqual('/',OC_Filesystem::getMountPoint('/some'));
$this->assertEqual('folder',OC_Filesystem::getInternalPath('/some/folder')); $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"));
}
}
} }
?> ?>
Loading…
Cancel
Save