From ebbb275d3241a9e9a16fa6c9e976d5aad742c866 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Wed, 23 Dec 2020 13:36:58 -0500 Subject: [PATCH] Fix various encoding/decoding issues --- src/parser.js | 9 ++++----- src/writer.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/parser.js b/src/parser.js index df921c4..47b44e7 100644 --- a/src/parser.js +++ b/src/parser.js @@ -43,7 +43,7 @@ function collectPosts(data, config) { // meta data isn't written to file, but is used to help with other things meta: { id: getPostId(post), - slug: decodeURI(getPostSlug(post)), + slug: getPostSlug(post), coverImageId: getPostCoverImageId(post), imageUrls: [] }, @@ -65,7 +65,7 @@ function getPostId(post) { } function getPostSlug(post) { - return post.post_name[0]; + return decodeURI(post.post_name[0]); } function getPostCoverImageId(post) { @@ -110,7 +110,7 @@ function processCategoryTags(post, domain) { return post.category .filter(category => category.$.domain === domain) - .map(({ $: attributes }) => attributes.nicename); + .map(({ $: attributes }) => decodeURI(attributes.nicename)); } function collectAttachedImages(data) { @@ -138,11 +138,10 @@ function collectScrapedImages(data) { matches.forEach(match => { // base the matched image URL relative to the post URL const url = new URL(match[1], postLink).href; - images.push({ id: -1, postId: postId, - url: url + url: decodeURI(url) }); }); }); diff --git a/src/writer.js b/src/writer.js index 18dc6bb..3f23955 100644 --- a/src/writer.js +++ b/src/writer.js @@ -110,7 +110,7 @@ async function loadImageFilePromise(imageUrl) { let buffer; try { buffer = await requestPromiseNative.get({ - url: imageUrl, + url: encodeURI(imageUrl), encoding: null, // preserves binary encoding headers: { 'User-Agent': 'wordpress-export-to-markdown'