From bb0a9625ade775b9b53868dbf82c1a97e465806b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cipriani=20Bandarra?= Date: Thu, 28 Apr 2022 18:42:54 +0100 Subject: [PATCH] Skips BOM on Web Manifests - Downloads manifest as String and trims before parsing the JSON. --- packages/core/src/lib/TwaGenerator.ts | 2 +- packages/core/src/lib/TwaManifest.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/lib/TwaGenerator.ts b/packages/core/src/lib/TwaGenerator.ts index 87e58d81..2e7bc591 100644 --- a/packages/core/src/lib/TwaGenerator.ts +++ b/packages/core/src/lib/TwaGenerator.ts @@ -273,7 +273,7 @@ export class TwaGenerator { } // We're writing as a string, but attempt to convert to check if it's a well-formed JSON. - const webManifestJson = await response.json(); + const webManifestJson = JSON.parse((await response.text()).trim()); // We want to ensure that "start_url" is the same used to launch the Trusted Web Activity. webManifestJson['start_url'] = twaManifest.startUrl; diff --git a/packages/core/src/lib/TwaManifest.ts b/packages/core/src/lib/TwaManifest.ts index 048faa30..37a82477 100644 --- a/packages/core/src/lib/TwaManifest.ts +++ b/packages/core/src/lib/TwaManifest.ts @@ -359,7 +359,7 @@ export class TwaManifest { */ static async fromWebManifest(url: string): Promise { const response = await fetchUtils.fetch(url); - const webManifest = await response.json(); + const webManifest = JSON.parse((await response.text()).trim()); const webManifestUrl: URL = new URL(url); return TwaManifest.fromWebManifestJson(webManifestUrl, webManifest); }