Skip to content

Commit f36b0b2

Browse files
committed
Updated code to use new path splitter instead of dirname/basename
1 parent 0166fa3 commit f36b0b2

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

lib/Sabre/DAV/Browser/Plugin.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,21 @@ public function httpPOSTHandler($method) {
100100
case 'mkcol' :
101101
if (isset($_POST['name']) && trim($_POST['name'])) {
102102
// Using basename() because we won't allow slashes
103-
$folderName = trim(basename($_POST['name']));
103+
list(, $folderName) = Sabre_DAV_URLUtil::splitPath(trim($_POST['name']));
104104
$this->server->createDirectory($this->server->getRequestUri() . '/' . $folderName);
105105
}
106106
break;
107107
case 'put' :
108108
if ($_FILES) $file = current($_FILES);
109109
else break;
110-
$newName = basename($file['name']);
110+
$newName = trim($file['name']);
111+
list(, $newName) = Sabre_DAV_URLUtil::splitPath(trim($file['name']));
111112
if (isset($_POST['name']) && trim($_POST['name']))
112-
$newName = trim(basename($_POST['name']));
113+
$newName = trim($_POST['name']);
114+
115+
// Making sure we only have a 'basename' component
116+
list(, $newName) = Sabre_DAV_URLUtil::splitPath($newName);
117+
113118

114119
if (is_uploaded_file($file['tmp_name'])) {
115120
$parent = $this->server->tree->getNodeForPath(trim($this->server->getRequestUri(),'/'));

lib/Sabre/DAV/Server.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,13 +1010,13 @@ public function getPropertiesForPath($path,$propertyNames = array(),$depth = 0)
10101010
*/
10111011
public function createFile($uri,$data) {
10121012

1013-
$parentUri = dirname($uri);
1014-
if ($parentUri=='.') $parentUri = '';
1013+
list($dir,$name) = Sabre_DAV_URLUtil::splitPath($uri);
1014+
10151015
if (!$this->broadcastEvent('beforeBind',array($uri))) return;
10161016
if (!$this->broadcastEvent('beforeCreateFile',array($uri,$data))) return;
10171017

1018-
$parent = $this->tree->getNodeForPath($parentUri);
1019-
$parent->createFile(basename($uri),$data);
1018+
$parent = $this->tree->getNodeForPath($dir);
1019+
$parent->createFile($name,$data);
10201020

10211021
$this->broadcastEvent('afterBind',array($uri));
10221022
}

lib/Sabre/DAV/TemporaryFileFilterPlugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ public function beforeCreateFile($uri,$data) {
134134
* temporary file storage.
135135
*
136136
* @param string $path
137-
* @return mixed
137+
* @return boolean|string
138138
*/
139139
protected function isTempFile($path) {
140140

141-
$tempPath = basename($path);
141+
// We're only interested in the basename.
142+
list(, $tempPath) = Sabre_DAV_URLUtil::splitPath($path);
142143

143144
$tempFiles = array(
144145
'/^\._(.*)$/', // OS/X resource forks

lib/Sabre/DAV/Tree.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ abstract function getNodeForPath($path);
3232
public function copy($sourcePath, $destinationPath) {
3333

3434
$sourceNode = $this->getNodeForPath($sourcePath);
35-
$destinationParent = $this->getNodeForPath(dirname($destinationPath));
36-
$this->copyNode($sourceNode,$destinationParent,basename($destinationPath));
35+
36+
// grab the dirname and basename components
37+
list($destinationDir, $destinationName) = Sabre_DAV_URLUtil::splitPath($destinationPath);
38+
39+
$destinationParent = $this->getNodeForPath($destinationDir);
40+
$this->copyNode($sourceNode,$destinationParent,$destinationName);
3741

3842
}
3943

@@ -46,9 +50,12 @@ public function copy($sourcePath, $destinationPath) {
4650
*/
4751
public function move($sourcePath, $destinationPath) {
4852

49-
if (dirname($sourcePath)==dirname($destinationPath)) {
53+
list($sourceDir, $sourceName) = Sabre_DAV_URLUtil::splitPath($sourcePath);
54+
list($destinationDir, $destinationName) = Sabre_DAV_URLUtil::splitPath($destinationPath);
55+
56+
if ($sourceDir===$destinationDir) {
5057
$renameable = $this->getNodeForPath($sourcePath);
51-
$renameable->setName(basename($destinationPath));
58+
$renameable->setName($destinationName);
5259
} else {
5360
$this->copy($sourcePath,$destinationPath);
5461
$this->getNodeForPath($sourcePath)->delete();

0 commit comments

Comments
 (0)