From 0be4ff48281dca7848dc68f01e4d4df04a67594a Mon Sep 17 00:00:00 2001
From: kmfd <47769987+kmfd@users.noreply.github.com>
Date: Sat, 8 Feb 2025 22:20:21 -0600
Subject: [PATCH 1/4] escapeHtml more chars and less repeating
---
src/build.js | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/build.js b/src/build.js
index ccf09fd541..4352d8d333 100644
--- a/src/build.js
+++ b/src/build.js
@@ -200,9 +200,25 @@ function readCfg(path) {
function escapeHtml(html) {
- return html.replaceAll('&', '&')
- .replaceAll('<', '<')
- .replaceAll('>', '>')
- .replaceAll('\'', ''')
- .replaceAll('"', '"');
+ const entities = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ '\'': ''',
+ '’': ''',
+ '‘': ''',
+ '“': '"',
+ '”': '"',
+ '': '"',
+ '': '"',
+ '’': ''',
+ '‘': ''',
+ };
+
+ return html.replace(/&(#8217|#8216);|&(?!#)|"|'|’|‘|“|”||<\/cite>|<(?!cite)|(?!/g, function(match) {
+ const replacement = entities[match] || match;
+ // console.log(`Matched: ${match}, Replaced with: ${replacement}`);
+ return replacement;
+ });
}
From 47e49f4368e47725d190bc8ec83e25c5cccc05af Mon Sep 17 00:00:00 2001
From: kmfd <47769987+kmfd@users.noreply.github.com>
Date: Sat, 8 Feb 2025 22:39:23 -0600
Subject: [PATCH 2/4] catch escapehtml error - no title
---
src/build.js | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/build.js b/src/build.js
index 4352d8d333..14712bf06d 100644
--- a/src/build.js
+++ b/src/build.js
@@ -29,7 +29,7 @@ const config = readCfg('./src/config.json');
const feeds = USE_CACHE ? {} : readCfg('./src/feeds.json');
const cache = USE_CACHE ? readCfg(CACHE_PATH) : {};
-await build({ config, feeds, cache, writeCache: WRITE });
+await build({ config, feeds, cache, writeCache: WRITE })
async function build({ config, feeds, cache, writeCache = false }) {
let allItems = cache.allItems || [];
@@ -115,9 +115,22 @@ async function build({ config, feeds, cache, writeCache = false }) {
if (redirect) item.link = `https://${redirect}${url.pathname}${url.search}`;
}
- // 5. escape html in titles
- item.title = escapeHtml(item.title);
- });
+
+ // 5. escape any html in the title
+ if (typeof item.title === 'string') {
+ try {
+ item.title = escapeHtml(item.title);
+ } catch (error) {
+ console.error('Error escaping HTML in title:', error);
+ }
+ } else {
+ console.log('Title is not a string:', item.title);
+ item.title = '(NO TITLE ON THIS ITEM)'
+ console.log('item.link:', item.link);
+ console.log('item.contentSnippet:', item.contentSnippet);
+ console.log(Object.keys(item));
+ }
+ });
// add to allItems
allItems = [...allItems, ...contents.items];
From b41d7f903f10e3c82c86da43a63f3f623861afaf Mon Sep 17 00:00:00 2001
From: kmfd <47769987+kmfd@users.noreply.github.com>
Date: Sun, 9 Feb 2025 23:32:02 -0600
Subject: [PATCH 3/4] Update build.js escapeHtml
---
src/build.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/build.js b/src/build.js
index 14712bf06d..b9ea60d1bc 100644
--- a/src/build.js
+++ b/src/build.js
@@ -29,7 +29,7 @@ const config = readCfg('./src/config.json');
const feeds = USE_CACHE ? {} : readCfg('./src/feeds.json');
const cache = USE_CACHE ? readCfg(CACHE_PATH) : {};
-await build({ config, feeds, cache, writeCache: WRITE })
+await build({ config, feeds, cache, writeCache: WRITE });
async function build({ config, feeds, cache, writeCache = false }) {
let allItems = cache.allItems || [];
From 714edae84fe5c7e47c76e659a497a5b3722c561f Mon Sep 17 00:00:00 2001
From: kmfd <47769987+kmfd@users.noreply.github.com>
Date: Sun, 9 Feb 2025 23:43:13 -0600
Subject: [PATCH 4/4] Update build.js escapeHtml
---
src/build.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/build.js b/src/build.js
index b9ea60d1bc..cda95a36b7 100644
--- a/src/build.js
+++ b/src/build.js
@@ -227,9 +227,11 @@ function escapeHtml(html) {
'': '"',
'’': ''',
'‘': ''',
+ '’': ''',
+ '‘': ''',
};
- return html.replace(/&(#8217|#8216);|&(?!#)|"|'|’|‘|“|”||<\/cite>|<(?!cite)|(?!/g, function(match) {
+ return html.replace(/&(#8217|#8216);|’|‘|&(?!([a-zA-Z0-9#]+;))|"|'|’|‘|“|”||<\/cite>|<(?!cite)|(?!/g, function(match) {
const replacement = entities[match] || match;
// console.log(`Matched: ${match}, Replaced with: ${replacement}`);
return replacement;