From e80d6a5f7b766501c2425c0590c7264f1281e219 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 16 Nov 2021 15:13:58 +0300 Subject: sanitize filename --- background.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'background.js') diff --git a/background.js b/background.js index a806e71..7718789 100644 --- a/background.js +++ b/background.js @@ -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, @@ -16,4 +17,10 @@ chrome.contextMenus.create({ "title": "Save to Downloads…", "contexts": ["image"], "onclick": downloadResource -}) \ No newline at end of file +}) + +function safeFileName(str) { + if (/[|"*?:<>]/.test(str)) + str = str.replace(/[\/\\|"*?:<>]/g, '_'); + return str +} \ No newline at end of file -- cgit v1.2.3