diff options
author | yami <34216515+kn-yami@users.noreply.github.com> | 2019-07-30 15:42:58 +0200 |
---|---|---|
committer | yami <34216515+kn-yami@users.noreply.github.com> | 2019-07-30 15:42:58 +0200 |
commit | f635feec77ad32c3e1251a91a145ebee185fee31 (patch) | |
tree | 736c9750af88906c312afaf5303f40d30c31d90e /devtools | |
parent | 23e68227a2e3f3946fa4fd5589f338e6b36a6e56 (diff) | |
download | UXP-f635feec77ad32c3e1251a91a145ebee185fee31.tar UXP-f635feec77ad32c3e1251a91a145ebee185fee31.tar.gz UXP-f635feec77ad32c3e1251a91a145ebee185fee31.tar.lz UXP-f635feec77ad32c3e1251a91a145ebee185fee31.tar.xz UXP-f635feec77ad32c3e1251a91a145ebee185fee31.zip |
Issue #1138 - Part 2: JSON Viewer should ignore BOM
Mozilla Bug 1395313
Diffstat (limited to 'devtools')
-rw-r--r-- | devtools/client/jsonview/json-viewer.js | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/devtools/client/jsonview/json-viewer.js b/devtools/client/jsonview/json-viewer.js index bf86ebbea..38cb6d7ec 100644 --- a/devtools/client/jsonview/json-viewer.js +++ b/devtools/client/jsonview/json-viewer.js @@ -13,24 +13,26 @@ define(function (require, exports, module) { const json = document.getElementById("json"); - let jsonData; - - try { - jsonData = JSON.parse(json.textContent); - } catch (err) { - jsonData = err + ""; - } - // Application state object. let input = { jsonText: json.textContent, jsonPretty: null, - json: jsonData, headers: window.headers, tabActive: 0, prettified: false }; + // Remove BOM, if present. + if (input.jsonText.startsWith("\ufeff")) { + input.jsonText = input.jsonText.slice(1); + } + + try { + input.json = JSON.parse(input.jsonText); + } catch (err) { + input.json = err; + } + json.remove(); /** @@ -59,7 +61,7 @@ define(function (require, exports, module) { theApp.setState({jsonText: input.jsonText}); } else { if (!input.jsonPretty) { - input.jsonPretty = JSON.stringify(jsonData, null, " "); + input.jsonPretty = JSON.stringify(input.json, null, " "); } theApp.setState({jsonText: input.jsonPretty}); } |