« get me outta code hell

data: language: tidy sanitizing functions - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-29 16:19:28 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-30 13:23:08 -0400
commitb4e8afb733cf191b3b5333f7aafddf0802d04b39 (patch)
treef78c73c66d9d40406b9b2d8332d02105fd79a9a9 /src
parent5a1a3d07101da6ed7453070d233dcbb1c0562364 (diff)
data: language: tidy sanitizing functions
Diffstat (limited to 'src')
-rw-r--r--src/data/things/language.js39
1 files changed, 11 insertions, 28 deletions
diff --git a/src/data/things/language.js b/src/data/things/language.js
index f91c981d..f8fe0106 100644
--- a/src/data/things/language.js
+++ b/src/data/things/language.js
@@ -242,10 +242,7 @@ export class Language extends Thing {
       // Sanitize string arguments in particular. These are taken to come from
       // (raw) data and may include special characters that aren't meant to be
       // rendered as HTML markup.
-      const optionPart = this.#sanitizeStringArg(optionValue, {
-        // TODO: Won't need to specify preserveType.
-        preserveType: true,
-      });
+      const optionPart = this.#sanitizeStringArg(optionValue);
 
       outputParts.push(languageText);
       outputParts.push(optionPart);
@@ -280,23 +277,17 @@ export class Language extends Thing {
   // treated by the browser as a tag. This does *not* have an effect on actual
   // html.Tag objects, which are treated as sanitized by default (so that they
   // can be nested inside strings at all).
-  #sanitizeStringArg(arg, {preserveType = false} = {}) {
+  #sanitizeStringArg(arg) {
     const escapeHTML = CacheableObject.getUpdateValue(this, 'escapeHTML');
-
     if (!escapeHTML) {
       throw new Error(`escapeHTML unavailable`);
     }
 
-    if (typeof arg !== 'string') {
-      // TODO: Preserving type will be the only behavior.
-      if (preserveType) {
-        return arg;
-      } else {
-        return arg.toString();
-      }
+    if (typeof arg === 'string') {
+      return escapeHTML(arg);
+    } else {
+      return arg;
     }
-
-    return escapeHTML(arg);
   }
 
   // Wraps the output of a formatting function in a no-name-nor-attributes
@@ -321,16 +312,11 @@ export class Language extends Thing {
   // contents of a slot directly, it should be manually sanitized with this
   // function first.
   sanitize(arg) {
-    const escapeHTML = CacheableObject.getUpdateValue(this, 'escapeHTML');
-
-    if (!escapeHTML) {
-      throw new Error(`escapeHTML unavailable`);
+    if (typeof arg === 'string') {
+      return this.#wrapSanitized(this.#sanitizeStringArg(arg));
+    } else {
+      return arg;
     }
-
-    return (
-      (typeof arg === 'string'
-        ? this.#wrapSanitized(escapeHTML(arg))
-        : arg));
   }
 
   formatDate(date) {
@@ -552,10 +538,7 @@ export class Language extends Thing {
       const markerValue = array[markerIndex];
 
       const languageText = template.slice(lastIndex, match.index);
-      const markerPart = this.#sanitizeStringArg(markerValue, {
-        // TODO: Won't need to specify preserveType.
-        preserveType: true,
-      });
+      const markerPart = this.#sanitizeStringArg(markerValue);
 
       outputParts.push(languageText);
       outputParts.push(markerPart);