From 191248a1ab5c77bbb1f07ad272dcf3adfc0ebf19 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 28 Feb 2022 20:49:48 +0100 Subject: [PATCH] Ignore non-string objects in image rewriting --- Models/ThemeConfig/Conversion/FixImages.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Models/ThemeConfig/Conversion/FixImages.ts b/Models/ThemeConfig/Conversion/FixImages.ts index aa463fa732..6da57f190e 100644 --- a/Models/ThemeConfig/Conversion/FixImages.ts +++ b/Models/ThemeConfig/Conversion/FixImages.ts @@ -116,7 +116,7 @@ export class FixImages extends DesugaringStep { this._knownImages = knownImages; } - convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson } { + convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson, warnings?: [] } { let url: URL; try { url = new URL(json.id) @@ -125,6 +125,7 @@ export class FixImages extends DesugaringStep { return {result: json} } + const warnings = [] const absolute = url.protocol + "//" + url.host let relative = url.protocol + "//" + url.host + url.pathname relative = relative.substring(0, relative.lastIndexOf("/")) @@ -134,6 +135,12 @@ export class FixImages extends DesugaringStep { if (self._knownImages.has(leaf)) { return leaf; } + + if(typeof leaf !== "string"){ + warnings.push("Found a non-string object while replacing images: "+JSON.stringify(leaf)) + return leaf; + } + if (leaf.startsWith("./")) { return relative + leaf.substring(1) } @@ -178,6 +185,7 @@ export class FixImages extends DesugaringStep { return { + warnings, result: json }; }