Commit 2d7c4fd9 authored by jsbell@chromium.org's avatar jsbell@chromium.org

Don't NFC normalize filenames in form data

When building the payload for POST data with files, Blink was
normalizing strings. Similar to crbug.com/427183, we're calling
normalizeAndEncode() when encode() is more appropriate, and matches
the behavior in other browsers.

BUG=341019
R=tkent@chromium.org

Review URL: https://codereview.chromium.org/1306073004

git-svn-id: svn://svn.chromium.org/blink/trunk@201590 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4b92e442
Verify that attachment filenames are not normalized
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS file.name is request.filename
PASS response.field is request.field
PASS response.filename is request.filename
PASS response.type is request.type
PASS response.content is request.content
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<title>Verify that attachment filenames are not normalized</title>
<script src="/js-test-resources/js-test.js"></script>
<script>
description(document.title);
var jsTestIsAsync = true;
var request = {
field: "attachment",
filename: decodeURIComponent("z%CC%87o%CC%81%C5%82c%CC%81.txt"),
type: "text/plain",
content: "hello world"
};
var file = new File([request.content], request.filename, {type: request.type});
shouldBe("file.name", "request.filename");
var data = new FormData();
data.append(request.field, file);
var xhr = new XMLHttpRequest();
var match, response;
xhr.open("POST", "resources/multipart-post-echo.php", true);
xhr.send(data);
xhr.onreadystatechange = function(e) {
if (xhr.readyState !== xhr.DONE)
return;
match = xhr.responseText.match(/^(.*)=(.*):(.*):(.*)$/);
response = {
field: match[1],
filename: match[2],
type: match[3],
content: match[4]
};
shouldBe("response.field", "request.field");
shouldBe("response.filename", "request.filename");
shouldBe("response.type", "request.type");
shouldBe("response.content", "request.content");
finishJSTest();
};
</script>
</body>
</html>
...@@ -168,7 +168,7 @@ void FormDataBuilder::addFilenameToMultiPartHeader(Vector<char>& buffer, const W ...@@ -168,7 +168,7 @@ void FormDataBuilder::addFilenameToMultiPartHeader(Vector<char>& buffer, const W
// FIXME: This loses data irreversibly if the filename includes characters you can't encode // FIXME: This loses data irreversibly if the filename includes characters you can't encode
// in the website's character set. // in the website's character set.
append(buffer, "; filename=\""); append(buffer, "; filename=\"");
appendQuotedString(buffer, encoding.normalizeAndEncode(filename, WTF::QuestionMarksForUnencodables)); appendQuotedString(buffer, encoding.encode(filename, WTF::QuestionMarksForUnencodables));
append(buffer, '"'); append(buffer, '"');
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment