summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-11-16 15:13:58 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-11-16 15:13:58 +0300
commite80d6a5f7b766501c2425c0590c7264f1281e219 (patch)
treea997a0e87e7aa3a7d7e03f770f49af61df0e6ee1
parentaa41a8caccbe8199f34785ec1bf168bf6e64dd2f (diff)
sanitize filenameHEADmaster
-rw-r--r--background.js9
-rw-r--r--manifest.json2
2 files changed, 9 insertions, 2 deletions
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
diff --git a/manifest.json b/manifest.json
index a1a89d4..5d1240d 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Save images to Downloads",
- "version": "1.0",
+ "version": "1.1",
"background": {
"scripts": ["background.js"]
},