« get me outta code hell

validators: handle sequences when finding nearby valid content - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-24 16:53:54 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-24 16:53:54 -0300
commitf91a3c38bc82d981746749d06981c5831ea13af9 (patch)
treeda6400fc4f04d3b2ac51457eff1fbc56f871f54f
parent0aa5a3841cb626b674ce88117c68fde20e174bfc (diff)
validators: handle sequences when finding nearby valid content
-rw-r--r--src/data/validators.js23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/data/validators.js b/src/data/validators.js
index 5bc8821..5d68131 100644
--- a/src/data/validators.js
+++ b/src/data/validators.js
@@ -443,24 +443,23 @@ for (const entry of illegalContentSpec) {
   }
 }
 
-const illegalContentRegexp =
-  new RegExp(
-    illegalContentSpec
-      .map(entry => entry.illegal)
-      .map(illegal => `${illegal}+`)
-      .join('|'),
-    'g');
-
-const illegalCharactersInContent =
+const illegalSequencesInContent =
   illegalContentSpec
     .map(entry => entry.illegal)
-    .join('');
+    .map(illegal =>
+      (illegal.length === 1
+        ? `${illegal}+`
+        : `(?:${illegal})+`))
+    .join('|');
+
+const illegalContentRegexp =
+  new RegExp(illegalSequencesInContent, 'g');
 
 const legalContentNearEndRegexp =
-  new RegExp(`[^\n${illegalCharactersInContent}]+$`);
+  new RegExp(`(?<=^|${illegalSequencesInContent})(?:(?!${illegalSequencesInContent}).)+$`);
 
 const legalContentNearStartRegexp =
-  new RegExp(`^[^\n${illegalCharactersInContent}]+`);
+  new RegExp(`^(?:(?!${illegalSequencesInContent}).)+`);
 
 const trimWhitespaceNearBothSidesRegexp =
   /^ +| +$/gm;