« get me outta code hell

data: validate commentary capitalization w/ non-global regex - 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-02-15 08:57:31 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-15 08:57:31 -0400
commit7a1b8e36b4be5aae117fe79eb07e1fbdaf516b8d (patch)
tree5fb20c19c898223a8c7d1bd1e79e5785651ffe52
parentd31c889df346b7579ce1afe0746fb4aa0ed8227d (diff)
data: validate commentary capitalization w/ non-global regex
-rw-r--r--src/data/validators.js5
-rw-r--r--src/util/wiki-data.js2
2 files changed, 4 insertions, 3 deletions
diff --git a/src/data/validators.js b/src/data/validators.js
index 718e9c57..cb321160 100644
--- a/src/data/validators.js
+++ b/src/data/validators.js
@@ -5,7 +5,7 @@ import printable_characters from 'printable-characters';
 const {strlen} = printable_characters;
 
 import {colors, ENABLE_COLOR} from '#cli';
-import {commentaryRegexCaseInsensitive, commentaryRegexCaseSensitive}
+import {commentaryRegexCaseInsensitive, commentaryRegexCaseSensitiveOneShot}
   from '#wiki-data';
 
 import {
@@ -333,8 +333,7 @@ export function isCommentary(commentaryText) {
         `(Check for missing "|-" in YAML, or a misshapen annotation)`);
     }
 
-    commentaryRegexCaseSensitive.lastIndex = 0;
-    if (!commentaryRegexCaseSensitive.test(ownInput)) {
+    if (!commentaryRegexCaseSensitiveOneShot.test(ownInput)) {
       throw new TypeError(
         `Miscapitalization in commentary heading:\n` +
         `${colors.red(`"${cut(ownInput, 60)}"`)}\n` +
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index cc3bbba3..cdbffffa 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -671,6 +671,8 @@ export const commentaryRegexCaseInsensitive =
   new RegExp(commentaryRegexRaw, 'gmi');
 export const commentaryRegexCaseSensitive =
   new RegExp(commentaryRegexRaw, 'gm');
+export const commentaryRegexCaseSensitiveOneShot =
+  new RegExp(commentaryRegexRaw);
 
 export function filterAlbumsByCommentary(albums) {
   return albums