8000 fix: incorrect Content-Disposition encoding by bigben0123 · Pull Request #25961 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: incorrect Content-Disposition encoding #25961

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

Merged
merged 8 commits into from
Oct 28, 2020
Merged

Conversation

bigben0123
Copy link
Contributor
@bigben0123 bigben0123 commented Oct 15, 2020

Description of Change

Closes #25628

Fixed by detecting the right charset using HttpContentDisposition.
Resolve if the filename's encoding is same as your local system charset, it can be showed correctly.

Checklist

Test is hard to write because the filename in http head cannot be encoded in GBK or other charset.

image

Release Notes

Notes: Fix webRequest module not recognizing the encoding of the filename in Content-Disposition header.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Oct 15, 2020
Copy link
Member
@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

Hey! thanks for this contribution 🎉 a few things here:

  1. Could you please fix lint?
  2. Could you please add a short sentence in the Notes section of the PR body explaining this fix?
  3. Could you please add a test for this behavior to ensure that it correctly addresses the issue?

@codebytere codebytere changed the title Fixed: the Filename in content-disposition Chaos fix: incorrect Content-Disposition encoding Oct 15, 2020
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Oct 16, 2020
@bigben0123 bigben0123 requested a review from codebytere October 20, 2020 03:11
@codebytere
Copy link
Member
codebytere commented Oct 20, 2020

@bigben0123

  1. Could you please add a test for this behavior to ensure that it correctly addresses the issue?

Unless this is something that can't be be tested, we'd like a regression test to ensure this addresses the behavior

Ah i see you added to the PR body:

Test is hard to write because the filename in http head cannot be encoded in GBK or other charset.

I'll take a look again tomorrow :)

net::HttpContentDisposition header(value, std::string());
std::string decodedFilename =
header.is_attachment() ? " attachement" : " inline";
decodedFilename += "; filename=" + header.filename();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the filename be wrapped with "?

Copy link
Contributor Author
@bigben0123 bigben0123 Oct 22, 2020

Choose a reason for hiding this comment

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

Not related to ".

@zcbenz
Copy link
Contributor
zcbenz commented Oct 20, 2020

Test is hard to write because the filename in http head cannot be encoded in GBK or other charset.

We should at least have a test to verify that, this change would not break normal Content-Disposition header.

@bigben0123
Copy link
Contributor Author

ast have a test to verify that, this change would not break normal

Normal test has passed.

@codebytere
Copy link
Member
codebytere commented Oct 22, 2020

@bigben0123 what is being asked of you is that you add a new test to directly test that this change does not break the normal, current functionality of the Content-Disposition header. This is not currently tested to this end.

@bigben0123 bigben0123 requested a review from zcbenz October 26, 2020 02:11
Copy link
Contributor
@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

The spec needs to test the code path of HttpResponseHeadersToV8, i.e. the code that converts the Content-Disposition response header to JS n webRequest module.

So we should also add a webRequest.onResponseStarted listener in the test to verify content-disposition is correctly passed. Something like this:

ses.webRequest.onResponseStarted((details) => {
  expect(details.responseHeaders['content-disposition']).to.equal([' attachement; filename=aa%CC%ECaa.txt'])
});

@bigben0123 bigben0123 requested a review from zcbenz October 27, 2020 07:52
@zcbenz zcbenz merged commit 84a42a0 into electron:master Oct 28, 2020
@welcome
Copy link
welcome bot commented Oct 28, 2020

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link
release-clerk bot commented Oct 28, 2020

Release Notes Persisted

Fix webRequest module not recognizing the encoding of the filename in Content-Disposition header.

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.

data in other charset like GBK in Content-disposition cannot be encoded correctly
3 participants
0