From c2428d2a136d2af4ed7235240308082db32cb3f8 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 2 Jan 2022 10:56:25 -0400 Subject: fix missing args errors not being thrown from to() --- src/util/urls.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/util') 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; -- cgit 1.3.0-6-gf8a5