From 2ed9af82f21f1390d507f04638157b63bfd4b949 Mon Sep 17 00:00:00 2001 From: sD Date: Wed, 25 Mar 2020 23:12:27 +0100 Subject: move encoding stuff to seperate js file --- webAO/encoding.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 webAO/encoding.js (limited to 'webAO/encoding.js') diff --git a/webAO/encoding.js b/webAO/encoding.js new file mode 100644 index 0000000..76e0b6d --- /dev/null +++ b/webAO/encoding.js @@ -0,0 +1,85 @@ +/** + * Escapes a string to AO1 escape codes. + * @param {string} estring the string to be escaped + */ +export function escapeChat(estring) { + return estring + .replace(/#/g, "") + .replace(/&/g, "") + .replace(/%/g, "") + .replace(/\$/g, ""); +} + +/** + * Unescapes a string to AO1 escape codes. + * @param {string} estring the string to be unescaped + */ +export function unescapeChat(estring) { + return estring + .replace(//g, "#") + .replace(//g, "&") + .replace(//g, "%") + .replace(//g, "$"); +} + +/** + * Escapes a string to be HTML-safe. + * + * XXX: This is unnecessary if we use `createTextNode` instead! + * @param {string} unsafe an unsanitized string + */ +export function safe_tags(unsafe) { + if (unsafe) { + return unsafe + .replace(/&/g, "&") + .replace(/ Date: Sat, 4 Apr 2020 14:34:28 +0200 Subject: use prepChat for music and more in general --- webAO/encoding.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'webAO/encoding.js') diff --git a/webAO/encoding.js b/webAO/encoding.js index 76e0b6d..3249617 100644 --- a/webAO/encoding.js +++ b/webAO/encoding.js @@ -82,4 +82,13 @@ export function decodeChat(estring) { } else { return estring; } +} + +/** + * XXX: a nasty hack made by gameboyprinter. + * @param {string} msg chat message to prepare for display + */ +export function prepChat(msg) { + // TODO: make this less awful + return unescapeChat(decodeChat(msg)); } \ No newline at end of file -- cgit From 3ca6d8c691fb52c272fef95f99573b9191c8530c Mon Sep 17 00:00:00 2001 From: sD Date: Mon, 13 Apr 2020 17:54:42 +0200 Subject: fix safe_tags --- webAO/encoding.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'webAO/encoding.js') diff --git a/webAO/encoding.js b/webAO/encoding.js index 3249617..71ebe53 100644 --- a/webAO/encoding.js +++ b/webAO/encoding.js @@ -31,10 +31,8 @@ export function unescapeChat(estring) { export function safe_tags(unsafe) { if (unsafe) { return unsafe - .replace(/&/g, "&") + .replace(/>/g, "&rt;") .replace(/