From 7899dd944d06f82e39119d7f01b1c8afb1ef855e Mon Sep 17 00:00:00 2001 From: kamran bigdely Date: Sat, 5 Apr 2025 23:41:21 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20an=20error=20that=20preventing=20to=20sav?= =?UTF-8?q?e=20image=20files=20using=20filenames=20that=20include=20query?= =?UTF-8?q?=20parameters=20(for=20example,=20"image-2.png=3Fw=3D671"=20or?= =?UTF-8?q?=20"image-3.png=3Fw=3D1024").=20Windows=20doesn=E2=80=99t=20all?= =?UTF-8?q?ow=20characters=20like=20=E2=80=9C=3F=E2=80=9D=20in=20filenames?= =?UTF-8?q?,=20so=20when=20the=20tool=20tries=20to=20open=20or=20save=20su?= =?UTF-8?q?ch=20a=20file,=20it=20fails=20with=20an=20ENOENT=20error.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/shared.js b/src/shared.js index c1a13c4..b62af44 100644 --- a/src/shared.js +++ b/src/shared.js @@ -73,6 +73,14 @@ export function buildPostPath(post, overrideConfig) { export function getFilenameFromUrl(url) { let filename = url.split('/').slice(-1)[0]; + + // Remove query parameters and hash fragments from filename + filename = filename.split('?')[0].split('#')[0]; + + // Replace any other invalid Windows filename characters + const invalidChars = /[<>:"\/\\|?*]/g; + filename = filename.replace(invalidChars, '_'); + try { filename = decodeURIComponent(filename) } catch (ex) {