mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-30 19:17:31 +09:00
Issue #1138 - Part 2: JSON Viewer should ignore BOM
Mozilla Bug 1395313
This commit is contained in:
parent
8f1e1f40c7
commit
32b3994a7b
1 changed files with 12 additions and 10 deletions
|
|
@ -13,24 +13,26 @@ define(function (require, exports, module) {
|
||||||
|
|
||||||
const json = document.getElementById("json");
|
const json = document.getElementById("json");
|
||||||
|
|
||||||
let jsonData;
|
|
||||||
|
|
||||||
try {
|
|
||||||
jsonData = JSON.parse(json.textContent);
|
|
||||||
} catch (err) {
|
|
||||||
jsonData = err + "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Application state object.
|
// Application state object.
|
||||||
let input = {
|
let input = {
|
||||||
jsonText: json.textContent,
|
jsonText: json.textContent,
|
||||||
jsonPretty: null,
|
jsonPretty: null,
|
||||||
json: jsonData,
|
|
||||||
headers: window.headers,
|
headers: window.headers,
|
||||||
tabActive: 0,
|
tabActive: 0,
|
||||||
prettified: false
|
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();
|
json.remove();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -59,7 +61,7 @@ define(function (require, exports, module) {
|
||||||
theApp.setState({jsonText: input.jsonText});
|
theApp.setState({jsonText: input.jsonText});
|
||||||
} else {
|
} else {
|
||||||
if (!input.jsonPretty) {
|
if (!input.jsonPretty) {
|
||||||
input.jsonPretty = JSON.stringify(jsonData, null, " ");
|
input.jsonPretty = JSON.stringify(input.json, null, " ");
|
||||||
}
|
}
|
||||||
theApp.setState({jsonText: input.jsonPretty});
|
theApp.setState({jsonText: input.jsonPretty});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue