mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #53539 from nextcloud/fix/validation-defaults
This commit is contained in:
commit
b95f96a85a
4 changed files with 9 additions and 9 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ class FilenameValidator implements IFilenameValidator {
|
|||
$forbiddenCharacters = $this->getForbiddenCharacters();
|
||||
|
||||
if ($charReplacement === null) {
|
||||
$charReplacement = array_diff([' ', '_', '-'], $forbiddenCharacters);
|
||||
$charReplacement = array_diff(['_', '-', ' '], $forbiddenCharacters);
|
||||
$charReplacement = reset($charReplacement) ?: '';
|
||||
}
|
||||
if (mb_strlen($charReplacement) !== 1) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ interface IFilenameValidator {
|
|||
* 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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ class FilenameValidatorTest extends TestCase {
|
|||
'.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'
|
||||
|
|
@ -492,13 +492,13 @@ class FilenameValidatorTest extends TestCase {
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue