Bug 1573786 - ManifestProcessor should throw error when parsing invalid JSON r=marcosc

Differential Revision: https://phabricator.services.mozilla.com/D42627

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Belén Albeza 2019-08-20 13:30:12 +00:00
parent 7249733689
commit 5ac210ec83
2 changed files with 8 additions and 2 deletions

View File

@ -93,7 +93,9 @@ var ManifestProcessor = {
let rawManifest = {};
try {
rawManifest = JSON.parse(jsonText);
} catch (e) {}
} catch (e) {
errors.push({ type: "json", error: e.message });
}
if (rawManifest === null) {
return null;
}

View File

@ -19,11 +19,15 @@ var invalidJson = ["", ` \t \n ${whiteSpace} `, "{", "{[[}"];
invalidJson.forEach((testString) => {
var expected = `Expect to recover from invalid JSON: ${testString}`;
data.jsonText = testString;
data.checkConformance = true;
var result = processor.process(data);
SimpleTest.is(result.start_url, docURL.href, expected);
SimpleTest.ok(
[...result.moz_validation].find(x => x.error && x.type === "json"),
"A JSON error message is included");
});
var validButUnhelpful = ["1", 1, "", "[{}]"];
var validButUnhelpful = ["1", 1, "[{}]"];
validButUnhelpful.forEach((testString) => {
var expected = `Expect to recover from valid JSON: ${testString}`;
data.jsonText = testString;