Skip to content

Commit

Permalink
fix: incorrect Content-Disposition serialization (#31694)
Browse files Browse the repository at this point in the history
* fix: incorrect Content-Disposition serialization

* test: fixup test

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Nov 4, 2021
1 parent e918fe6 commit 8c84255
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions shell/browser/api/electron_api_web_request.cc
Expand Up @@ -133,8 +133,10 @@ v8::Local<v8::Value> HttpResponseHeadersToV8(
net::HttpContentDisposition header(value, std::string());
std::string decodedFilename =
header.is_attachment() ? " attachment" : " inline";
decodedFilename += "; filename=" + header.filename();
value = decodedFilename;
// The filename must be encased in double quotes for serialization
// to happen correctly.
std::string filename = "\"" + header.filename() + "\"";
value = decodedFilename + "; filename=" + filename;
}
if (!values)
values = response_headers.SetKey(key, base::ListValue());
Expand Down
2 changes: 1 addition & 1 deletion spec-main/api-web-request-spec.ts
Expand Up @@ -354,7 +354,7 @@ describe('webRequest module', () => {

it('does not change content-disposition header by default', async () => {
ses.webRequest.onHeadersReceived((details, callback) => {
expect(details.responseHeaders!['content-disposition']).to.deep.equal([' attachment; filename=aa中aa.txt']);
expect(details.responseHeaders!['content-disposition']).to.deep.equal([' attachment; filename="aa中aa.txt"']);
callback({});
});
const { data, headers } = await ajax(defaultURL + 'contentDisposition');
Expand Down

0 comments on commit 8c84255

Please sign in to comment.