Skip to content

Commit 9353d55

Browse files
author
Andreu Botella
authored
Add test cases for newline handling in form payloads
1 parent 647c99c commit 9353d55

File tree

10 files changed

+1290
-76
lines changed

10 files changed

+1290
-76
lines changed

FileAPI/file/send-file-formdata-controls.tentative.html renamed to FileAPI/file/send-file-formdata-controls.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8" />
3-
<title>FormData: Upload files named using controls (tentative)</title>
4-
<!--
5-
NOTE: This test is tentative because encoding for filename
6-
control characters is not yet standardized.
7-
-->
3+
<title>FormData: Upload files named using controls</title>
84
<link
95
rel="help"
106
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data"

FileAPI/file/send-file-formdata-punctuation.tentative.html renamed to FileAPI/file/send-file-formdata-punctuation.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8" />
3-
<title>FormData: Upload files named using punctuation (tentative)</title>
4-
<!--
5-
NOTE: This test is tentative because encoding for filename
6-
punctuation characters is not yet standardized.
7-
-->
3+
<title>FormData: Upload files named using punctuation</title>
84
<link
95
rel="help"
106
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data"

FileAPI/support/send-file-formdata-helper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,21 @@ const formDataPostFileUploadTest = ({
7070
}`,
7171
);
7272

73-
const asName = fileBaseName.replace(/[\r\n"]/g, encodeURIComponent);
73+
const asValue = fileBaseName.replace(/\r\n?|\n/g, "\r\n");
74+
const asName = asValue.replace(/[\r\n"]/g, encodeURIComponent);
75+
const asFilename = fileBaseName.replace(/[\r\n"]/g, encodeURIComponent);
7476
const expectedText = [
7577
boundary,
7678
'Content-Disposition: form-data; name="filename"',
7779
"",
78-
fileBaseName,
80+
asValue,
7981
boundary,
8082
`Content-Disposition: form-data; name="${asName}"`,
8183
"",
8284
"filename",
8385
boundary,
8486
`Content-Disposition: form-data; name="file"; ` +
85-
`filename="${asName}"`,
87+
`filename="${asFilename}"`,
8688
"Content-Type: text/plain",
8789
"",
8890
kTestChars,

0 commit comments

Comments
 (0)