Skip to content

Commit 14ed764

Browse files
committed
Newsfeed: Convert HTML entities to characters
1 parent 7e58b38 commit 14ed764

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ _This release is scheduled to be released on 2023-07-01._
2525
- Use node v19 in github workflow (replacing v14)
2626
- Refactor formatTime into common util function for default modules
2727
- Refactor some calendar methods into own class and added tests for them
28+
- Properly convert newsfeed titles
2829

2930
### Fixed
3031

modules/default/newsfeed/newsfeed.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ Module.register("newsfeed", {
215215
return true;
216216
}, this);
217217
}
218+
219+
// HTML entity conversion: dummy textarea for conversion and regex for safe matching
220+
const entity_regex = /&(?:#x[a-f0-9]+|#[0-9]+|[a-z0-9]+);?/gi;
221+
const entity_converter = document.createElement("textarea");
222+
218223
newsItems.forEach((item) => {
219224
//Remove selected tags from the beginning of rss feed items (title or description)
220225
if (this.config.removeStartTags === "title" || this.config.removeStartTags === "both") {
@@ -251,6 +256,12 @@ Module.register("newsfeed", {
251256
}
252257
}
253258
}
259+
260+
//Convert HTML entities to characters
261+
item.title = item.title.replace(entity_regex, (t) => {
262+
entity_converter.innerHTML = t;
263+
return entity_converter.textContent;
264+
});
254265
});
255266

256267
// get updated news items and broadcast them

0 commit comments

Comments
 (0)