sanitize filename

This commit is contained in:
Evgeny Zinoviev 2021-11-16 15:13:58 +03:00
parent aa41a8cacc
commit e80d6a5f7b
2 changed files with 9 additions and 2 deletions

View File

@ -4,6 +4,7 @@ function downloadResource(info, tab) {
let filename = url.substring(url.lastIndexOf('/')+1)
if (filename.indexOf('?') !== false)
filename = filename.substring(0, filename.indexOf('?'))
filename = safeFileName(filename)
chrome.downloads.download({
url,
@ -17,3 +18,9 @@ chrome.contextMenus.create({
"contexts": ["image"],
"onclick": downloadResource
})
function safeFileName(str) {
if (/[|"*?:<>]/.test(str))
str = str.replace(/[\/\\|"*?:<>]/g, '_');
return str
}

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Save images to Downloads",
"version": "1.0",
"version": "1.1",
"background": {
"scripts": ["background.js"]
},