Skip to content

Commit ae04a74

Browse files
committed
fix: correct permissions and target in File and UploadedFile move()
1 parent 70c99eb commit ae04a74

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

system/Files/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
170170
throw FileException::forUnableToMove($this->getBasename(), $targetPath, strip_tags($error['message']));
171171
}
172172

173-
@chmod($destination, 0777 & ~umask());
173+
@chmod($destination, 0666 & ~umask());
174174

175175
return new self($destination);
176176
}

system/HTTP/Files/UploadedFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
159159
throw HTTPException::forMoveFailed(basename($this->path), $targetPath, $message);
160160
}
161161

162-
@chmod($targetPath, 0777 & ~umask());
162+
@chmod($destination, 0666 & ~umask());
163163

164164
// Success, so store our new information
165165
$this->path = $targetPath;

tests/system/Files/FileWithVfsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,13 @@ public function testMoveReturnsNewInstance(): void
150150
$this->assertInstanceOf(File::class, $file);
151151
$this->assertSame($destination . '/apple.php', $file->getPathname());
152152
}
153+
154+
public function testMovePermissions(): void
155+
{
156+
$destination = $this->start . 'baker';
157+
$this->file->move($destination);
158+
159+
$expectedPerms = 0666 & ~umask();
160+
$this->assertSame($expectedPerms, $this->root->getChild('baker/apple.php')->getPermissions());
161+
}
153162
}

tests/system/HTTP/Files/FileMovingTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function testMove(): void
9898

9999
$this->assertTrue($this->root->hasChild('destination/' . $finalFilename . '.txt'));
100100
$this->assertTrue($this->root->hasChild('destination/' . $finalFilename . '_1.txt'));
101+
$this->assertSame(0666 & ~umask(), $this->root->getChild('destination/' . $finalFilename . '.txt')->getPermissions());
101102
}
102103

103104
public function testMoveSanitizesClientNameByDefault(): void

0 commit comments

Comments
 (0)