aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-03-30 03:36:51 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-03-30 03:36:51 +0200
commit62f4a2edffdbf5f4fc0b5a1b8cfe70f32e594938 (patch)
tree686e2ff89e2ed47ba808b6080f2544a861ac6332
parentUnset XDG_DATA_HOME in env file. (diff)
downloadcalp-62f4a2edffdbf5f4fc0b5a1b8cfe70f32e594938.tar.gz
calp-62f4a2edffdbf5f4fc0b5a1b8cfe70f32e594938.tar.xz
Handle XML entities slightly better in user-additions.js.
-rw-r--r--static/user/user-additions.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/static/user/user-additions.js b/static/user/user-additions.js
index 3b39b3ad..6d944b86 100644
--- a/static/user/user-additions.js
+++ b/static/user/user-additions.js
@@ -1,12 +1,21 @@
window.formatters.set('description', (el, d) => {
if (/<br\/?>/.exec(d)) {
- /* Assume that the text is HTML iff in contains a <br/> tag */
+ /* Assume that the text is HTML iff it contains a <br/> tag */
let parser = new DOMParser();
let doc = parser.parseFromString(d, 'text/html');
el.replaceChildren(doc.body);
} else {
- /* Otherwise it should be plain(er) text, parse "all" links */
- el.innerHTML = d.replaceAll(/https?:\/\/\S+/g, '<a href="$&">$&</a>');
+ /* Otherwise it should be plain(er) text, parse "all" links
+ (and reserved XML characters)
+ */
+ // TODO replace with something that doesn't use innerHTML */
+ el.innerHTML = d
+ .replaceAll(/</g, '&lt;')
+ .replaceAll(/>/g, '&gt;')
+ .replaceAll(/&/g, '&amp;')
+ .replaceAll(/'/g, '&apos;')
+ .replaceAll(/"/g, '&quot;')
+ .replaceAll(/https?:\/\/\S+/g, '<a href="$&">$&</a>')
}
})