Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Feature: Windows compatible filenames
And invoking occ with "files:windows-compatible-filenames --enable"
And invoking occ with "files:sanitize-filenames user0"
Then as "user0" the file "/2*2=4.txt" does not exist
And as "user0" the file "/2 2=4.txt" exists
And as "user0" the file "/2_2=4.txt" exists

Scenario: renaming a file with invalid character and replacement setup
Given As an "admin"
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/FilenameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function sanitizeFilename(string $name, ?string $charReplacement = null):
$forbiddenCharacters = $this->getForbiddenCharacters();

if ($charReplacement === null) {
$charReplacement = array_diff([' ', '_', '-'], $forbiddenCharacters);
$charReplacement = array_diff(['_', '-', ' '], $forbiddenCharacters);
$charReplacement = reset($charReplacement) ?: '';
}
if (mb_strlen($charReplacement) !== 1) {
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Files/IFilenameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function validateFilename(string $filename): void;
* If no sanitizing is needed the same name is returned.
*
* @param string $name The filename to sanitize
* @param null|string $charReplacement Character to use for replacing forbidden ones - by default space, dash or underscore is used if allowed.
* @param null|string $charReplacement Character to use for replacing forbidden ones - by default underscore, dash or space is used if allowed.
* @throws \InvalidArgumentException if no character replacement was given (and the default could not be applied) or the replacement is not valid.
* @since 32.0.0
*/
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/Files/FilenameValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public static function dataSanitizeFilename(): array {
'.thumbs.db', ['.htaccess'], ['.thumbs'], [], [], '.thumbs (renamed).db'
],
'invalid character' => [
'a: b.txt', ['.htaccess'], [], [], [':'], 'a b.txt',
'a: b.txt', ['.htaccess'], [], [], [':'], 'a_ b.txt',
],
'invalid extension' => [
'a: b.txt', ['.htaccess'], [], ['.txt'], [], 'a: b'
Expand Down Expand Up @@ -492,13 +492,13 @@ public function testSanitizeFilenameCharacterReplacement(
public static function dataSanitizeFilenameCharacterReplacement(): array {
return [
'default' => [
'foo*bar', ['*'], null, 'foo bar'
'foo*bar', ['*'], null, 'foo_bar'
],
'default - space not allowed' => [
'foo*bar', ['*', ' '], null, 'foo_bar'
'default - underscore not allowed' => [
'foo*bar', ['*', '_'], null, 'foo-bar'
],
'default - space and underscore not allowed' => [
'foo*bar', ['*', ' ', '_'], null, 'foo-bar'
'default - dash and underscore not allowed' => [
'foo*bar', ['*', '-', '_'], null, 'foo bar'
],
'default - no replacement' => [
'foo*bar', ['*', ' ', '_', '-'], null, null
Expand Down
Loading