« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/urls.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index 12a1651f..a30cc81b 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -69,16 +69,20 @@ export function generateURLs(urlSpec) {
 
         const toHelper = (delimiterMode) => (key, ...args) => {
             const {
-                value: {[delimiterMode]: template},
-                group: {[groupSymbol]: toGroup}
+                value: {[delimiterMode]: template}
             } = getValueForFullKey(relative, key);
 
-            let result = template.replaceAll(/<([0-9]+)>/g, (match, n) => args[n]);
+            let missing = 0;
+            let result = template.replaceAll(/<([0-9]+)>/g, (match, n) => {
+                if (n < args.length) {
+                    return args[n];
+                } else {
+                    missing++;
+                }
+            });
 
-            // Kinda hacky lol, 8ut it works.
-            const missing = result.match(/<([0-9]+)>/g);
             if (missing) {
-                throw new Error(`Expected ${missing[missing.length - 1]} arguments, got ${args.length}`);
+                throw new Error(`Expected ${missing + args.length} arguments, got ${args.length} (key ${key}, args [${args}])`);
             }
 
             return result;