Make getFileNameExtension properly handle directory separators

This commit is contained in:
toasted-nutbread 2020-04-19 10:18:31 -04:00
parent 7faaf4e457
commit 16893b52b1

View File

@ -16,13 +16,13 @@
*/ */
const mediaUtility = (() => { const mediaUtility = (() => {
function getFileNameExtension(fileName) { function getFileNameExtension(path) {
const match = /\.[^.]*$/.exec(fileName); const match = /\.[^./\\]*$/.exec(path);
return match !== null ? match[0] : ''; return match !== null ? match[0] : '';
} }
function getImageMediaTypeFromFileName(fileName) { function getImageMediaTypeFromFileName(path) {
switch (getFileNameExtension(fileName).toLowerCase()) { switch (getFileNameExtension(path).toLowerCase()) {
case '.apng': case '.apng':
return 'image/apng'; return 'image/apng';
case '.bmp': case '.bmp':