Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove BOM encoding from manifest #2175

Merged
merged 5 commits into from
Jun 21, 2017
Merged

Conversation

wardpeet
Copy link
Collaborator

@wardpeet wardpeet commented May 7, 2017

Fixes issue #1702

@wardpeet wardpeet force-pushed the BOM-manifest branch 2 times, most recently from 022422b to 1c213ab Compare May 7, 2017 14:51
@paulirish
Copy link
Member

I didn't read the full history of #1702 but i have some recent news:

AFAIK the chrome manifest parser had no problem with BOM but devtools' application panel did. (is that confirmed?)
This was fixed just a few weeks back though: https://codereview.chromium.org/2837943003

so afaik, there won't be a problem with BOM parsing in chrome anymore.

With that status, should we still throw in this situation?

@wardpeet
Copy link
Collaborator Author

wardpeet commented May 8, 2017

Let me give it a spin if we get our manifest back from devtools.
If we do get it, this PR is useless 😄

Before the devtools fix it gave a null manifest

I'll close it myself when i've tested it

@paulirish
Copy link
Member

hmmmm!

we might still have a problem then.

the devtools fix was only in the frontend, so yeah looks like we'll need this patch afterall.

(real chrome doesn't use the protocol method. that's the difference here)

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than throw error let's just remove the BOM and let it proceed.

@wardpeet wardpeet changed the title Throw error when manifest is BOM encoding Remove BOM encoding from manifest May 12, 2017
@wardpeet
Copy link
Collaborator Author

wardpeet commented May 12, 2017

@paulirish fixed! ;) issue was still present in lighthouse

@paulirish
Copy link
Member

paulirish commented May 12, 2017

Nice I also tested with the fixture in https://bugs.chromium.org/p/chromium/issues/detail?id=706926 which is what we validated the devtools fix against.
lg.

image

};

const promises = [];
promises.push(manifestGather.afterPass(getDriver(manifestWithBOM))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will throw even if still bad...won't it show with an "isn't valid JSON" debugString?

It would be good to check the result from afterPass...result.raw should have the raw string passed in, so it should have length equal to manifestWithBOM minus the BOM. And it would be good to check some of the parsed values to make sure it's being parsed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn forgot to change the test text as we throwed before it should say pass when manifest has BOM

@@ -36,6 +37,12 @@ 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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the compatibility like if we skip the Buffer slicing for the check (so files without a BOM don't have to go through that) and do const isBomEncoded = response.data.charCodeAt(0) === 65279;. Does that work cross platform?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can test on windows, linux & mac just to be sure

@wardpeet
Copy link
Collaborator Author

@brendankenny tested your change on Windows 10, mac and linux and seems to work for me.

@paulirish
Copy link
Member

Awesome. Thanks for testing that out. We'll let this PR and TTFB chill until we cut 2.0, and then we'll incorporate. Sorry for making you wait!

@wardpeet
Copy link
Collaborator Author

@paulirish you never have to say sorry 😉

It's no urgent bug so it can wait

@wardpeet
Copy link
Collaborator Author

@brendankenny everything should be ready to go

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

I pushed a last commit for some minor promise formatting in the test file just to expedite landing :)

Otherwise, verified it works with a real run with BOM-encoded manifest and that the new test fails if the BOM is removed from the test manifest.

I'll wait for Travis, but otherwise LGTM!

@codecov
Copy link

codecov bot commented Jun 21, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@5add27d). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2175   +/-   ##
=========================================
  Coverage          ?   83.69%           
=========================================
  Files             ?      177           
  Lines             ?     5785           
  Branches          ?      802           
=========================================
  Hits              ?     4842           
  Misses            ?      923           
  Partials          ?       20
Impacted Files Coverage Δ
lighthouse-core/gather/gatherers/manifest.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5add27d...dd4a1c1. Read the comment docs.

@paulirish paulirish merged commit b347c70 into GoogleChrome:master Jun 21, 2017
@wardpeet wardpeet deleted the BOM-manifest branch July 24, 2017 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants