From b80a41245c33c2e95a04bb56ddaf5422f5a9f49c Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 13 Nov 2023 12:15:27 +0100 Subject: [PATCH] Fix indexes in script --- src/Models/ThemeConfig/Conversion/Conversion.ts | 2 +- .../ThemeConfig/Conversion/ConversionContext.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Models/ThemeConfig/Conversion/Conversion.ts b/src/Models/ThemeConfig/Conversion/Conversion.ts index f2ebd427c..745ce2ce7 100644 --- a/src/Models/ThemeConfig/Conversion/Conversion.ts +++ b/src/Models/ThemeConfig/Conversion/Conversion.ts @@ -110,7 +110,7 @@ export class Each extends Conversion { values[i]?.["id"] !== undefined ? values[i]?.["id"] : "" ) } - const context_ = c.enter(i - 1) + const context_ = c.enter(i) const r = step.convert(values[i], context_) result.push(r) } diff --git a/src/Models/ThemeConfig/Conversion/ConversionContext.ts b/src/Models/ThemeConfig/Conversion/ConversionContext.ts index 88fdcb771..2a0e5e848 100644 --- a/src/Models/ThemeConfig/Conversion/ConversionContext.ts +++ b/src/Models/ThemeConfig/Conversion/ConversionContext.ts @@ -25,7 +25,14 @@ export class ConversionContext { if (this.path.some((p) => typeof p === "object" || p === "[object Object]")) { throw "ConversionMessage: got an object as path entry:" + JSON.stringify(path) } + if (this.path.some((p) => typeof p === "number" && p < 0)) { + if (!ConversionContext.reported) { + ConversionContext.reported = true + console.trace("ConversionContext: got a path containing a negative number") + } + } } + private static reported = false public static construct(path: (string | number)[], operation: string[]) { return new ConversionContext([], [...path], [...operation]) @@ -71,6 +78,10 @@ export class ConversionContext { public enter(key: string | number | (string | number)[]) { if (!Array.isArray(key)) { + if (typeof key === "number" && key < 0) { + console.trace("Invalid key") + throw "Invalid key: <0" + } return new ConversionContext(this.messages, [...this.path, key], this.operation) } return new ConversionContext(this.messages, [...this.path, ...key], this.operation)