Skip to content

Commit

Permalink
Fix bomb check
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed May 12, 2017
1 parent a994c11 commit cc44ef6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 6 additions & 10 deletions lighthouse-core/gather/gatherers/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ class Manifest extends Gatherer {
afterPass(options) {
return options.driver.getAppManifest()
.then(response => {
const isBomEncoded = Buffer.from(response.data).slice(0, BOM_ENCODING.length)
.equals(new Buffer(BOM_ENCODING));
if (isBomEncoded) {
response.data = Buffer.from(response.data).slice(BOM_ENCODING.length).toString();
}

return manifestParser(response.data, response.url, options.url);
})
.catch(err => {
if (err === 'No web app manifest found.') {
return null;
}

<<<<<<< HEAD
return Promise.reject(err);
=======
const isBomEncoded = Buffer.from(response.data).slice(1, 4)
.equals(new Buffer(BOM_ENCODING));
if (isBomEncoded) {
throw new Error('Manifest is encoded with BOM. Please remove the BOM encoding');
}

return manifestParser(response.data, response.url, options.url);
>>>>>>> Throw error when manifest is BOM encoding
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-core/test/gather/gatherers/manifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe('Manifest gatherer', () => {
const getDriver = (data) => {
return {
driver: {
sendCommand() {
getAppManifest() {
return Promise.resolve({
data: JSON.stringify(data),
data,
errors: [],
url: EXAMPLE_MANIFEST_URL
});
Expand All @@ -72,8 +72,8 @@ describe('Manifest gatherer', () => {
const promises = [];
promises.push(manifestGather.afterPass(getDriver(manifestWithBOM))
.then(
_ => assert.ok(false),
err => assert.ok(err.message.includes('Manifest is encoded with BOM.'))
_ => assert.ok(true),
_ => assert.ok(false)
)
);

Expand Down

0 comments on commit cc44ef6

Please sign in to comment.