Ignore non-string objects in image rewriting

This commit is contained in:
Pieter Vander Vennet 2022-02-28 20:49:48 +01:00
parent 8ae679d075
commit 191248a1ab

View file

@ -116,7 +116,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
this._knownImages = knownImages; this._knownImages = knownImages;
} }
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson } { convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson, warnings?: [] } {
let url: URL; let url: URL;
try { try {
url = new URL(json.id) url = new URL(json.id)
@ -125,6 +125,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
return {result: json} return {result: json}
} }
const warnings = []
const absolute = url.protocol + "//" + url.host const absolute = url.protocol + "//" + url.host
let relative = url.protocol + "//" + url.host + url.pathname let relative = url.protocol + "//" + url.host + url.pathname
relative = relative.substring(0, relative.lastIndexOf("/")) relative = relative.substring(0, relative.lastIndexOf("/"))
@ -134,6 +135,12 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
if (self._knownImages.has(leaf)) { if (self._knownImages.has(leaf)) {
return 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("./")) { if (leaf.startsWith("./")) {
return relative + leaf.substring(1) return relative + leaf.substring(1)
} }
@ -178,6 +185,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
return { return {
warnings,
result: json result: json
}; };
} }