From 7899dd944d06f82e39119d7f01b1c8afb1ef855e Mon Sep 17 00:00:00 2001 From: kamran bigdely Date: Sat, 5 Apr 2025 23:41:21 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20an=20error=20that=20preventing=20to?= =?UTF-8?q?=20save=20image=20files=20using=20filenames=20that=20include=20?= =?UTF-8?q?query=20parameters=20(for=20example,=20"image-2.png=3Fw=3D671"?= =?UTF-8?q?=20or=20"image-3.png=3Fw=3D1024").=20Windows=20doesn=E2=80=99t?= =?UTF-8?q?=20allow=20characters=20like=20=E2=80=9C=3F=E2=80=9D=20in=20fil?= =?UTF-8?q?enames,=20so=20when=20the=20tool=20tries=20to=20open=20or=20sav?= =?UTF-8?q?e=20such=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) { From adcd7c672f6de77ea7de7adf68ed94b8a8e75d1f Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Wed, 16 Apr 2025 16:37:47 -0400 Subject: [PATCH 2/2] Allow cover images to have query string --- src/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.js b/src/parser.js index d538e3a..3363c05 100644 --- a/src/parser.js +++ b/src/parser.js @@ -122,7 +122,7 @@ function collectAttachedImages(allPostData) { // filter to certain image file types .filter((attachment) => { const url = attachment.childValue('attachment_url'); - return url && (/\.(gif|jpe?g|png|webp)$/i).test(url); + return url && (/\.(gif|jpe?g|png|webp)(\?|$)/i).test(url); }) .map((attachment) => ({ id: attachment.childValue('post_id'),