Catch URIError

This commit is contained in:
Will Boyd
2024-03-01 12:54:27 -05:00
parent e71fb12ac8
commit 47df034ba0
+8 -1
View File
@@ -1,5 +1,12 @@
function getFilenameFromUrl(url) {
return decodeURIComponent(url.split('/').slice(-1)[0]);
let filename = url.split('/').slice(-1)[0];
try {
filename = decodeURIComponent(filename)
} catch (ex) {
// filename could not be decoded because of improper encoding with %
// leave filename as-is and continue
}
return filename;
}
exports.getFilenameFromUrl = getFilenameFromUrl;