« 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
path: root/src
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-05-01 07:06:07 -0300
commit705e1b75448c3b64b4281841d4f45063e4bf903c (patch)
tree9db9ff4afd88151ba102f1103c98a47e6fcc41a8 /src
parentd67db6a4d59ca9880a7ae5596c89550bd35c03c2 (diff)
validators: handle sequences when finding nearby valid content
Diffstat (limited to 'src')
-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 5bc88210..5d681311 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;