fix for filename sanitize/cut

This commit is contained in:
Milos Stojanovic
2019-09-09 10:10:59 +02:00
parent 5c1480cd95
commit 4258e68d8f
2 changed files with 8 additions and 10 deletions

View File

@@ -137,15 +137,6 @@ class Tmpfs implements Service, TmpfsInterface
);
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
$ext = pathinfo($filename, PATHINFO_EXTENSION);
return mb_strcut(
pathinfo($filename, PATHINFO_FILENAME),
0,
255 - ($ext ? strlen($ext) + 1 : 0),
(string) mb_detect_encoding($filename)
).(
$ext ? '.'.$ext : ''
);
return mb_substr($filename, 0, 255);
}
}

View File

@@ -157,5 +157,12 @@ class TmpfsTest extends TestCase
// with invalid chars
$this->assertEquals('..--s-u---pe----rm---an-.t-xt..--', $this->invokeMethod($this->service, 'sanitizeFilename', ["../\\s\"u<:>pe////rm?*|an\\.t\txt../;"]));
// oversized
$this->assertEquals(
'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345',
$this->invokeMethod($this->service, 'sanitizeFilename', [
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456'
]));
}
}