From 288fd3423c6b26d03ca102aea96b57a29abd95e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bl=C3=A4sta?= Date: Mon, 6 Mar 2023 13:18:28 +0100 Subject: [PATCH] fix: try to fix invalid backslash in json --- src/getfeatureinfo.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/getfeatureinfo.js b/src/getfeatureinfo.js index 7b87294ec..9a32afdfe 100644 --- a/src/getfeatureinfo.js +++ b/src/getfeatureinfo.js @@ -69,9 +69,20 @@ function getFeatureInfoUrl({ if (res.error) { return []; } - return res.json(); + return res.text(); }) - .then(json => { + .then(text => { + let json = {}; + try { + json = JSON.parse(text); + } catch (error) { + if (error instanceof SyntaxError) { + // Maybe bad escaped character, retry with escaping backslash + json = JSON.parse(text.replaceAll('\\', '\\\\')); + } else { + console.error(error); + } + } if (json.features.length > 0) { const copyJson = json; copyJson.features.forEach((item, i) => {