Truly independent web browser
LibWeb: Import form submission character encoding tests
Andreas Kling20949202daa5
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 202b73aea86..cdbf85709cc 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -249,6 +249,11 @@ Text/input/wpt-import/custom-elements/form-associated/form-disabled-callback.htm; Form tests use WPT Python handlers, substitutions, or root-relative resources.Text/input/wpt-import/html/semantics/forms/the-label-element/label-attributes.sub.html+Text/input/wpt-import/FileAPI/file/send-file-form-windows-1252.html+Text/input/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.html+Text/input/wpt-import/FileAPI/file/send-file-form-x-user-defined.html+Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.html+Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.html; Navigates an existing named iframe to /common/blank.html.Text/input/wpt-import/html/browsers/the-window-object/window-open-noopener-existing-iframe.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.txt b/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.txtnew file mode 100644index 00000000000..7bf4c9ec38e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 6 tests++1 Pass+5 Fail+Pass Upload file-for-upload-in-form.txt (ASCII) in ISO-2022-JP form+Fail Upload file-for-upload-in-form-.txt (x-user-defined) in ISO-2022-JP form+Fail Upload file-for-upload-in-form-☺😂.txt (windows-1252) in ISO-2022-JP form+Fail Upload file-for-upload-in-form-★星★.txt (JIS X 0201 and JIS X 0208) in ISO-2022-JP form+Fail Upload file-for-upload-in-form-☺😂.txt (Unicode) in ISO-2022-JP form+Fail Upload file-for-upload-in-form-ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ.txt (Unicode) in ISO-2022-JP form\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-windows-1252.txt b/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-windows-1252.txtnew file mode 100644index 00000000000..3e74eb8fe8f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-windows-1252.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 6 tests++1 Pass+5 Fail+Pass Upload file-for-upload-in-form.txt (ASCII) in windows-1252 form+Fail Upload file-for-upload-in-form-.txt (x-user-defined) in windows-1252 form+Fail Upload file-for-upload-in-form-☺😂.txt (windows-1252) in windows-1252 form+Fail Upload file-for-upload-in-form-★星★.txt (JIS X 0201 and JIS X 0208) in windows-1252 form+Fail Upload file-for-upload-in-form-☺😂.txt (Unicode) in windows-1252 form+Fail Upload file-for-upload-in-form-ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ.txt (Unicode) in windows-1252 form\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-x-user-defined.txt b/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-x-user-defined.txtnew file mode 100644index 00000000000..9e83a7dd087--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/FileAPI/file/send-file-form-x-user-defined.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 6 tests++1 Pass+5 Fail+Pass Upload file-for-upload-in-form.txt (ASCII) in x-user-defined form+Fail Upload file-for-upload-in-form-.txt (x-user-defined) in x-user-defined form+Fail Upload file-for-upload-in-form-☺😂.txt (windows-1252) in x-user-defined form+Fail Upload file-for-upload-in-form-★星★.txt (JIS X 0201 and JIS X 0208) in x-user-defined form+Fail Upload file-for-upload-in-form-☺😂.txt (Unicode) in x-user-defined form+Fail Upload file-for-upload-in-form-ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ.txt (Unicode) in x-user-defined form\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.txtnew file mode 100644index 00000000000..fd7fd78c637--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.txt@@ -0,0 +1,68 @@+Harness status: OK++Found 62 tests++56 Pass+6 Fail+Pass multipart/form-data: Basic test (normal form)+Pass multipart/form-data: Basic test (formdata event)+Pass multipart/form-data: Basic File test (normal form)+Pass multipart/form-data: Basic File test (formdata event)+Pass multipart/form-data: 0x00 in name (normal form)+Pass multipart/form-data: 0x00 in name (formdata event)+Pass multipart/form-data: 0x00 in value (normal form)+Pass multipart/form-data: 0x00 in value (formdata event)+Pass multipart/form-data: 0x00 in filename (normal form)+Pass multipart/form-data: 0x00 in filename (formdata event)+Pass multipart/form-data: \n in name (normal form)+Pass multipart/form-data: \n in name (formdata event)+Pass multipart/form-data: \r in name (normal form)+Pass multipart/form-data: \r in name (formdata event)+Pass multipart/form-data: \r\n in name (normal form)+Pass multipart/form-data: \r\n in name (formdata event)+Pass multipart/form-data: \n\r in name (normal form)+Pass multipart/form-data: \n\r in name (formdata event)+Pass multipart/form-data: \n in value (normal form)+Pass multipart/form-data: \n in value (formdata event)+Pass multipart/form-data: \r in value (normal form)+Pass multipart/form-data: \r in value (formdata event)+Pass multipart/form-data: \r\n in value (normal form)+Pass multipart/form-data: \r\n in value (formdata event)+Pass multipart/form-data: \n\r in value (normal form)+Pass multipart/form-data: \n\r in value (formdata event)+Pass multipart/form-data: \n in filename (normal form)+Pass multipart/form-data: \n in filename (formdata event)+Pass multipart/form-data: \r in filename (normal form)+Pass multipart/form-data: \r in filename (formdata event)+Pass multipart/form-data: \r\n in filename (normal form)+Pass multipart/form-data: \r\n in filename (formdata event)+Pass multipart/form-data: \n\r in filename (normal form)+Pass multipart/form-data: \n\r in filename (formdata event)+Pass multipart/form-data: double quote in name (normal form)+Pass multipart/form-data: double quote in name (formdata event)+Pass multipart/form-data: double quote in value (normal form)+Pass multipart/form-data: double quote in value (formdata event)+Pass multipart/form-data: double quote in filename (normal form)+Pass multipart/form-data: double quote in filename (formdata event)+Pass multipart/form-data: single quote in name (normal form)+Pass multipart/form-data: single quote in name (formdata event)+Pass multipart/form-data: single quote in value (normal form)+Pass multipart/form-data: single quote in value (formdata event)+Pass multipart/form-data: single quote in filename (normal form)+Pass multipart/form-data: single quote in filename (formdata event)+Pass multipart/form-data: backslash in name (normal form)+Pass multipart/form-data: backslash in name (formdata event)+Pass multipart/form-data: backslash in value (normal form)+Pass multipart/form-data: backslash in value (formdata event)+Pass multipart/form-data: backslash in filename (normal form)+Pass multipart/form-data: backslash in filename (formdata event)+Pass multipart/form-data: non-ASCII in name and value (normal form)+Pass multipart/form-data: non-ASCII in name and value (formdata event)+Pass multipart/form-data: non-ASCII in filename (normal form)+Pass multipart/form-data: non-ASCII in filename (formdata event)+Fail multipart/form-data: characters not in encoding in name and value (normal form)+Fail multipart/form-data: characters not in encoding in name and value (formdata event)+Fail multipart/form-data: character not in encoding in filename (normal form)+Fail multipart/form-data: character not in encoding in filename (formdata event)+Fail multipart/form-data: lone surrogate in name and value (normal form)+Fail multipart/form-data: lone surrogate in name and value (formdata event)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.txtnew file mode 100644index 00000000000..58a2a6c55e4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.txt@@ -0,0 +1,68 @@+Harness status: OK++Found 62 tests++56 Pass+6 Fail+Pass text/plain: Basic test (normal form)+Pass text/plain: Basic test (formdata event)+Pass text/plain: Basic File test (normal form)+Pass text/plain: Basic File test (formdata event)+Pass text/plain: 0x00 in name (normal form)+Pass text/plain: 0x00 in name (formdata event)+Pass text/plain: 0x00 in value (normal form)+Pass text/plain: 0x00 in value (formdata event)+Pass text/plain: 0x00 in filename (normal form)+Pass text/plain: 0x00 in filename (formdata event)+Pass text/plain: \n in name (normal form)+Pass text/plain: \n in name (formdata event)+Pass text/plain: \r in name (normal form)+Pass text/plain: \r in name (formdata event)+Pass text/plain: \r\n in name (normal form)+Pass text/plain: \r\n in name (formdata event)+Pass text/plain: \n\r in name (normal form)+Pass text/plain: \n\r in name (formdata event)+Pass text/plain: \n in value (normal form)+Pass text/plain: \n in value (formdata event)+Pass text/plain: \r in value (normal form)+Pass text/plain: \r in value (formdata event)+Pass text/plain: \r\n in value (normal form)+Pass text/plain: \r\n in value (formdata event)+Pass text/plain: \n\r in value (normal form)+Pass text/plain: \n\r in value (formdata event)+Pass text/plain: \n in filename (normal form)+Pass text/plain: \n in filename (formdata event)+Pass text/plain: \r in filename (normal form)+Pass text/plain: \r in filename (formdata event)+Pass text/plain: \r\n in filename (normal form)+Pass text/plain: \r\n in filename (formdata event)+Pass text/plain: \n\r in filename (normal form)+Pass text/plain: \n\r in filename (formdata event)+Pass text/plain: double quote in name (normal form)+Pass text/plain: double quote in name (formdata event)+Pass text/plain: double quote in value (normal form)+Pass text/plain: double quote in value (formdata event)+Pass text/plain: double quote in filename (normal form)+Pass text/plain: double quote in filename (formdata event)+Pass text/plain: single quote in name (normal form)+Pass text/plain: single quote in name (formdata event)+Pass text/plain: single quote in value (normal form)+Pass text/plain: single quote in value (formdata event)+Pass text/plain: single quote in filename (normal form)+Pass text/plain: single quote in filename (formdata event)+Pass text/plain: backslash in name (normal form)+Pass text/plain: backslash in name (formdata event)+Pass text/plain: backslash in value (normal form)+Pass text/plain: backslash in value (formdata event)+Pass text/plain: backslash in filename (normal form)+Pass text/plain: backslash in filename (formdata event)+Pass text/plain: non-ASCII in name and value (normal form)+Pass text/plain: non-ASCII in name and value (formdata event)+Pass text/plain: non-ASCII in filename (normal form)+Pass text/plain: non-ASCII in filename (formdata event)+Fail text/plain: characters not in encoding in name and value (normal form)+Fail text/plain: characters not in encoding in name and value (formdata event)+Fail text/plain: character not in encoding in filename (normal form)+Fail text/plain: character not in encoding in filename (formdata event)+Fail text/plain: lone surrogate in name and value (normal form)+Fail text/plain: lone surrogate in name and value (formdata event)\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/resources/echo-content-escaped.py b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/resources/echo-content-escaped.pynew file mode 100644index 00000000000..5370e1e46ac--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/resources/echo-content-escaped.py@@ -0,0 +1,26 @@+from wptserve.utils import isomorphic_encode++# Outputs the request body, with controls and non-ASCII bytes escaped+# (b"\n" becomes b"\\x0a"), and with backslashes doubled.+# As a convenience, CRLF newlines are left as is.++def escape_byte(byte):+ # Convert int byte into a single-char binary string.+ byte = bytes([byte])+ if b"\0" <= byte <= b"\x1F" or byte >= b"\x7F":+ return b"\\x%02x" % ord(byte)+ if byte == b"\\":+ return b"\\\\"+ return byte++def main(request, response):++ headers = [(b"X-Request-Method", isomorphic_encode(request.method)),+ (b"X-Request-Content-Length", request.headers.get(b"Content-Length", b"NO")),+ (b"X-Request-Content-Type", request.headers.get(b"Content-Type", b"NO")),+ # Avoid any kind of content sniffing on the response.+ (b"Content-Type", b"text/plain; charset=UTF-8")]++ content = b"".join(map(escape_byte, request.body)).replace(b"\\x0d\\x0a", b"\r\n")++ return headers, contentdiff --git a/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.html b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.htmlnew file mode 100644index 00000000000..14eb8babedd--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-iso-2022-jp.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<meta charset="utf-8">+<meta name=timeout content=long>+<title>Upload files in ISO-2022-JP form</title>+<link rel="help"+ href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">+<link rel="help"+ href="https://html.spec.whatwg.org/multipage/dnd.html#datatransferitemlist">+<link rel="help"+ href="https://w3c.github.io/FileAPI/#file-constructor">+<link rel="author" title="Benjamin C. Wiley Sittler"+ href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../support/send-file-form-helper.js"></script>+<script>+'use strict';++formPostFileUploadTest({+ fileNameSource: 'ASCII',+ fileBaseName: 'file-for-upload-in-form.txt',+ formEncoding: 'ISO-2022-JP',+ expectedEncodedBaseName: 'file-for-upload-in-form.txt',+});++formPostFileUploadTest({+ fileNameSource: 'x-user-defined',+ fileBaseName: 'file-for-upload-in-form-\uF7F0\uF793\uF783\uF7A0.txt',+ formEncoding: 'ISO-2022-JP',+ expectedEncodedBaseName: (+ 'file-for-upload-in-form-.txt'),+});++formPostFileUploadTest({+ fileNameSource: 'windows-1252',+ fileBaseName: 'file-for-upload-in-form-☺😂.txt',+ formEncoding: 'ISO-2022-JP',+ expectedEncodedBaseName: (+ 'file-for-upload-in-form-☺😂.txt'),+});++formPostFileUploadTest({+ fileNameSource: 'JIS X 0201 and JIS X 0208',+ fileBaseName: 'file-for-upload-in-form-★星★.txt',+ formEncoding: 'ISO-2022-JP',+ expectedEncodedBaseName: 'file-for-upload-in-form-\x1B$B!z@1!z\x1B(B.txt',+});++formPostFileUploadTest({+ fileNameSource: 'Unicode',+ fileBaseName: 'file-for-upload-in-form-☺😂.txt',+ formEncoding: 'ISO-2022-JP',+ expectedEncodedBaseName: 'file-for-upload-in-form-☺😂.txt',+});++formPostFileUploadTest({+ fileNameSource: 'Unicode',+ fileBaseName: `file-for-upload-in-form-${kTestChars}.txt`,+ formEncoding: 'ISO-2022-JP',+ expectedEncodedBaseName: `file-for-upload-in-form-${+ kTestFallbackIso2022jp+ }.txt`,+});++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-windows-1252.html b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-windows-1252.htmlnew file mode 100644index 00000000000..33a40b86ab1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-windows-1252.html@@ -0,0 +1,62 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Upload files in Windows-1252 form</title>+<link rel="help"+ href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">+<link rel="help"+ href="https://html.spec.whatwg.org/multipage/dnd.html#datatransferitemlist">+<link rel="help"+ href="https://w3c.github.io/FileAPI/#file-constructor">+<link rel="author" title="Benjamin C. Wiley Sittler"+ href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../support/send-file-form-helper.js"></script>+<script>+'use strict';++formPostFileUploadTest({+ fileNameSource: 'ASCII',+ fileBaseName: 'file-for-upload-in-form.txt',+ formEncoding: 'windows-1252',+ expectedEncodedBaseName: 'file-for-upload-in-form.txt',+});++formPostFileUploadTest({+ fileNameSource: 'x-user-defined',+ fileBaseName: 'file-for-upload-in-form-\uF7F0\uF793\uF783\uF7A0.txt',+ formEncoding: 'windows-1252',+ expectedEncodedBaseName: 'file-for-upload-in-form-.txt',+});++formPostFileUploadTest({+ fileNameSource: 'windows-1252',+ fileBaseName: 'file-for-upload-in-form-☺😂.txt',+ formEncoding: 'windows-1252',+ expectedEncodedBaseName: 'file-for-upload-in-form-\xE2\x98\xBA\xF0\x9F\x98\x82.txt',+});++formPostFileUploadTest({+ fileNameSource: 'JIS X 0201 and JIS X 0208',+ fileBaseName: 'file-for-upload-in-form-★星★.txt',+ formEncoding: 'windows-1252',+ expectedEncodedBaseName: 'file-for-upload-in-form-★星★.txt',+});++formPostFileUploadTest({+ fileNameSource: 'Unicode',+ fileBaseName: 'file-for-upload-in-form-☺😂.txt',+ formEncoding: 'windows-1252',+ expectedEncodedBaseName: 'file-for-upload-in-form-☺😂.txt',+});++formPostFileUploadTest({+ fileNameSource: 'Unicode',+ fileBaseName: `file-for-upload-in-form-${kTestChars}.txt`,+ formEncoding: 'windows-1252',+ expectedEncodedBaseName: `file-for-upload-in-form-${+ kTestFallbackWindows1252+ }.txt`,+});++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-x-user-defined.html b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-x-user-defined.htmlnew file mode 100644index 00000000000..ca163d17004--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/FileAPI/file/send-file-form-x-user-defined.html@@ -0,0 +1,63 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Upload files in x-user-defined form</title>+<link rel="help"+ href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">+<link rel="help"+ href="https://html.spec.whatwg.org/multipage/dnd.html#datatransferitemlist">+<link rel="help"+ href="https://w3c.github.io/FileAPI/#file-constructor">+<link rel="author" title="Benjamin C. Wiley Sittler"+ href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../support/send-file-form-helper.js"></script>+<script>+'use strict';++formPostFileUploadTest({+ fileNameSource: 'ASCII',+ fileBaseName: 'file-for-upload-in-form.txt',+ formEncoding: 'x-user-defined',+ expectedEncodedBaseName: 'file-for-upload-in-form.txt',+});++formPostFileUploadTest({+ fileNameSource: 'x-user-defined',+ fileBaseName: 'file-for-upload-in-form-\uF7F0\uF793\uF783\uF7A0.txt',+ formEncoding: 'x-user-defined',+ expectedEncodedBaseName: 'file-for-upload-in-form-\xF0\x93\x83\xA0.txt',+});++formPostFileUploadTest({+ fileNameSource: 'windows-1252',+ fileBaseName: 'file-for-upload-in-form-☺😂.txt',+ formEncoding: 'x-user-defined',+ expectedEncodedBaseName: ('file-for-upload-in-form-' ++ '☺😂.txt'),+});++formPostFileUploadTest({+ fileNameSource: 'JIS X 0201 and JIS X 0208',+ fileBaseName: 'file-for-upload-in-form-★星★.txt',+ formEncoding: 'x-user-defined',+ expectedEncodedBaseName: 'file-for-upload-in-form-★星★.txt',+});++formPostFileUploadTest({+ fileNameSource: 'Unicode',+ fileBaseName: 'file-for-upload-in-form-☺😂.txt',+ formEncoding: 'x-user-defined',+ expectedEncodedBaseName: 'file-for-upload-in-form-☺😂.txt',+});++formPostFileUploadTest({+ fileNameSource: 'Unicode',+ fileBaseName: `file-for-upload-in-form-${kTestChars}.txt`,+ formEncoding: 'x-user-defined',+ expectedEncodedBaseName: `file-for-upload-in-form-${+ kTestFallbackXUserDefined+ }.txt`,+});++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/FileAPI/support/send-file-form-helper.js b/Tests/LibWeb/Text/input/wpt-import/FileAPI/support/send-file-form-helper.jsnew file mode 100644index 00000000000..d6adf21ec33--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/FileAPI/support/send-file-form-helper.js@@ -0,0 +1,282 @@+'use strict';++// See /FileAPI/file/resources/echo-content-escaped.py+function escapeString(string) {+ return string.replace(/\\/g, "\\\\").replace(+ /[^\x20-\x7E]/g,+ (x) => {+ let hex = x.charCodeAt(0).toString(16);+ if (hex.length < 2) hex = "0" + hex;+ return `\\x${hex}`;+ },+ ).replace(/\\x0d\\x0a/g, "\r\n");+}++// Rationale for this particular test character sequence, which is+// used in filenames and also in file contents:+//+// - ABC~ ensures the string starts with something we can read to+// ensure it is from the correct source; ~ is used because even+// some 1-byte otherwise-ASCII-like parts of ISO-2022-JP+// interpret it differently.+// - ‾¥ are inside a single-byte range of ISO-2022-JP and help+// diagnose problems due to filesystem encoding or locale+// - ≈ is inside IBM437 and helps diagnose problems due to filesystem+// encoding or locale+// - ¤ is inside Latin-1 and helps diagnose problems due to+// filesystem encoding or locale; it is also the "simplest" case+// needing substitution in ISO-2022-JP+// - ・ is inside a single-byte range of ISO-2022-JP in some variants+// and helps diagnose problems due to filesystem encoding or locale;+// on the web it is distinct when decoding but unified when encoding+// - ・ is inside a double-byte range of ISO-2022-JP and helps+// diagnose problems due to filesystem encoding or locale+// - • is inside Windows-1252 and helps diagnose problems due to+// filesystem encoding or locale and also ensures these aren't+// accidentally turned into e.g. control codes+// - ∙ is inside IBM437 and helps diagnose problems due to filesystem+// encoding or locale+// - · is inside Latin-1 and helps diagnose problems due to+// filesystem encoding or locale and also ensures HTML named+// character references (e.g. ·) are not used+// - ☼ is inside IBM437 shadowing C0 and helps diagnose problems due to+// filesystem encoding or locale and also ensures these aren't+// accidentally turned into e.g. control codes+// - ★ is inside ISO-2022-JP on a non-Kanji page and makes correct+// output easier to spot+// - 星 is inside ISO-2022-JP on a Kanji page and makes correct+// output easier to spot+// - 🌟 is outside the BMP and makes incorrect surrogate pair+// substitution detectable and ensures substitutions work+// correctly immediately after Kanji 2-byte ISO-2022-JP+// - 星 repeated here ensures the correct codec state is used+// after a non-BMP substitution+// - ★ repeated here also makes correct output easier to spot+// - ☼ is inside IBM437 shadowing C0 and helps diagnose problems due to+// filesystem encoding or locale and also ensures these aren't+// accidentally turned into e.g. control codes and also ensures+// substitutions work correctly immediately after non-Kanji+// 2-byte ISO-2022-JP+// - · is inside Latin-1 and helps diagnose problems due to+// filesystem encoding or locale and also ensures HTML named+// character references (e.g. ·) are not used+// - ∙ is inside IBM437 and helps diagnose problems due to filesystem+// encoding or locale+// - • is inside Windows-1252 and again helps diagnose problems+// due to filesystem encoding or locale+// - ・ is inside a double-byte range of ISO-2022-JP and helps+// diagnose problems due to filesystem encoding or locale+// - ・ is inside a single-byte range of ISO-2022-JP in some variants+// and helps diagnose problems due to filesystem encoding or locale;+// on the web it is distinct when decoding but unified when encoding+// - ¤ is inside Latin-1 and helps diagnose problems due to+// filesystem encoding or locale; again it is a "simple"+// substitution case+// - ≈ is inside IBM437 and helps diagnose problems due to filesystem+// encoding or locale+// - ¥‾ are inside a single-byte range of ISO-2022-JP and help+// diagnose problems due to filesystem encoding or locale+// - ~XYZ ensures earlier errors don't lead to misencoding of+// simple ASCII+//+// Overall the near-symmetry makes common I18N mistakes like+// off-by-1-after-non-BMP easier to spot. All the characters+// are also allowed in Windows Unicode filenames.+const kTestChars = 'ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ';++// The kTestFallback* strings represent the expected byte sequence from+// encoding kTestChars with the given encoding with "html" replacement+// mode, isomorphic-decoded. That means, characters that can't be+// encoded in that encoding get HTML-escaped, but no further+// `escapeString`-like escapes are needed.+const kTestFallbackUtf8 = (+ "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" ++ "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" ++ "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" ++ "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"+);++const kTestFallbackIso2022jp = (+ ("ABC~\x1B(J~\\≈¤\x1B$B!&!&\x1B(B•∙·☼\x1B$B!z@1\x1B(B🌟" ++ "\x1B$B@1!z\x1B(B☼·∙•\x1B$B!&!&\x1B(B¤≈\x1B(J\\~\x1B(B~XYZ")+ .replace(/[^\0-\x7F]/gu, (x) => `&#${x.codePointAt(0)};`)+);++const kTestFallbackWindows1252 = (+ "ABC~‾\xA5≈\xA4・・\x95∙\xB7☼★星🌟星★☼\xB7∙\x95・・\xA4≈\xA5‾~XYZ".replace(+ /[^\0-\xFF]/gu,+ (x) => `&#${x.codePointAt(0)};`,+ )+);++const kTestFallbackXUserDefined = kTestChars.replace(+ /[^\0-\x7F]/gu,+ (x) => `&#${x.codePointAt(0)};`,+);++// formPostFileUploadTest - verifies multipart upload structure and+// numeric character reference replacement for filenames, field names,+// and field values using form submission.+//+// Uses /FileAPI/file/resources/echo-content-escaped.py to echo the+// upload POST with controls and non-ASCII bytes escaped. This is done+// because navigations whose response body contains [\0\b\v] may get+// treated as a download, which is not what we want. Use the+// `escapeString` function to replicate that kind of escape (note that+// it takes an isomorphic-decoded string, not a byte sequence).+//+// Fields in the parameter object:+//+// - fileNameSource: purely explanatory and gives a clue about which+// character encoding is the source for the non-7-bit-ASCII parts of+// the fileBaseName, or Unicode if no smaller-than-Unicode source+// contains all the characters. Used in the test name.+// - fileBaseName: the not-necessarily-just-7-bit-ASCII file basename+// used for the constructed test file. Used in the test name.+// - formEncoding: the acceptCharset of the form used to submit the+// test file. Used in the test name.+// - expectedEncodedBaseName: the expected formEncoding-encoded+// version of fileBaseName, isomorphic-decoded. That means, characters+// that can't be encoded in that encoding get HTML-escaped, but no+// further `escapeString`-like escapes are needed.+const formPostFileUploadTest = ({+ fileNameSource,+ fileBaseName,+ formEncoding,+ expectedEncodedBaseName,+}) => {+ promise_test(async testCase => {++ if (document.readyState !== 'complete') {+ await new Promise(resolve => addEventListener('load', resolve));+ }++ const formTargetFrame = Object.assign(document.createElement('iframe'), {+ name: 'formtargetframe',+ });+ document.body.append(formTargetFrame);+ testCase.add_cleanup(() => {+ document.body.removeChild(formTargetFrame);+ });++ const form = Object.assign(document.createElement('form'), {+ acceptCharset: formEncoding,+ action: '/FileAPI/file/resources/echo-content-escaped.py',+ method: 'POST',+ enctype: 'multipart/form-data',+ target: formTargetFrame.name,+ });+ document.body.append(form);+ testCase.add_cleanup(() => {+ document.body.removeChild(form);+ });++ // Used to verify that the browser agrees with the test about+ // which form charset is used.+ form.append(Object.assign(document.createElement('input'), {+ type: 'hidden',+ name: '_charset_',+ }));++ // Used to verify that the browser agrees with the test about+ // field value replacement and encoding independently of file system+ // idiosyncracies.+ form.append(Object.assign(document.createElement('input'), {+ type: 'hidden',+ name: 'filename',+ value: fileBaseName,+ }));++ // Same, but with name and value reversed to ensure field names+ // get the same treatment.+ form.append(Object.assign(document.createElement('input'), {+ type: 'hidden',+ name: fileBaseName,+ value: 'filename',+ }));++ const fileInput = Object.assign(document.createElement('input'), {+ type: 'file',+ name: 'file',+ });+ form.append(fileInput);++ // Removes c:\fakepath\ or other pseudofolder and returns just the+ // final component of filePath; allows both / and \ as segment+ // delimiters.+ const baseNameOfFilePath = filePath => filePath.split(/[\/\\]/).pop();+ await new Promise(resolve => {+ const dataTransfer = new DataTransfer;+ dataTransfer.items.add(+ new File([kTestChars], fileBaseName, {type: 'text/plain'}));+ fileInput.files = dataTransfer.files;+ // For historical reasons .value will be prefixed with+ // c:\fakepath\, but the basename should match the file name+ // exposed through the newer .files[0].name API. This check+ // verifies that assumption.+ assert_equals(+ baseNameOfFilePath(fileInput.files[0].name),+ baseNameOfFilePath(fileInput.value),+ `The basename of the field's value should match its files[0].name`);+ form.submit();+ formTargetFrame.onload = resolve;+ });++ const formDataText = formTargetFrame.contentDocument.body.textContent;+ const formDataLines = formDataText.split('\n');+ if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {+ --formDataLines.length;+ }+ assert_greater_than(+ formDataLines.length,+ 2,+ `${fileBaseName}: multipart form data must have at least 3 lines: ${+ JSON.stringify(formDataText)+ }`);+ const boundary = formDataLines[0];+ assert_equals(+ formDataLines[formDataLines.length - 1],+ boundary + '--',+ `${fileBaseName}: multipart form data must end with ${boundary}--: ${+ JSON.stringify(formDataText)+ }`);++ const asValue = expectedEncodedBaseName.replace(/\r\n?|\n/g, "\r\n");+ const asName = asValue.replace(/[\r\n"]/g, encodeURIComponent);+ const asFilename = expectedEncodedBaseName.replace(/[\r\n"]/g, encodeURIComponent);++ // The response body from echo-content-escaped.py has controls and non-ASCII+ // bytes escaped, so any caller-provided field that might contain such bytes+ // must be passed to `escapeString`, after any other expected+ // transformations.+ const expectedText = [+ boundary,+ 'Content-Disposition: form-data; name="_charset_"',+ '',+ formEncoding,+ boundary,+ 'Content-Disposition: form-data; name="filename"',+ '',+ // Unlike for names and filenames, multipart/form-data values don't escape+ // \r\n linebreaks, and when they're read from an iframe they become \n.+ escapeString(asValue).replace(/\r\n/g, "\n"),+ boundary,+ `Content-Disposition: form-data; name="${escapeString(asName)}"`,+ '',+ 'filename',+ boundary,+ `Content-Disposition: form-data; name="file"; ` ++ `filename="${escapeString(asFilename)}"`,+ 'Content-Type: text/plain',+ '',+ escapeString(kTestFallbackUtf8),+ boundary + '--',+ ].join('\n');++ assert_true(+ formDataText.startsWith(expectedText),+ `Unexpected multipart-shaped form data received:\n${+ formDataText+ }\nExpected:\n${expectedText}`);+ }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);+};diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/enctypes-helper.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/enctypes-helper.jsnew file mode 100644index 00000000000..0f0d68163da--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/enctypes-helper.js@@ -0,0 +1,187 @@+// This file exposes the `formSubmissionTemplate` function, which can be used+// to create tests for the form submission encoding of various enctypes:+//+// const urlencodedTest = formSubmissionTemplate(+// "application/x-www-form-urlencoded",+// (expected, _actualFormBody) => expected+// );+//+// urlencodedTest({+// name: "a",+// value: "b",+// expected: "a=b",+// formEncoding: "UTF-8", // optional+// description: "Simple urlencoded test"+// });+//+// The above call to `urlencodedTest` tests the urlencoded form submission for a+// form whose entry list contains a single entry with name "a" and value "b",+// and it checks that the form payload matches the `expected` property after+// isomorphic-encoding.+//+// Since per the spec no normalization of the form entries should happen before+// the actual form encoding, each call to `urlencodedTest` will in fact add two+// tests: one submitting the entry as a form control (marked "normal form"), and+// one adding the entry through the `formdata` event (marked "formdata event").+// Both cases are compared against the same expected value.+//+// Since multipart/form-data boundary strings can't be predicted ahead of time,+// the second parameter of `formSubmissionTemplate` allows transforming the+// expected value passed to each test. The second argument of that callback+// is the actual form body (isomorphic-decoded). When this callback is used, the+// `expected` property doesn't need to be a string.++(() => {+ // Using echo-content-escaped.py rather than+ // /fetch/api/resources/echo-content.py to work around WebKit not+ // percent-encoding \x00, which causes the response to be detected as+ // a binary file and served as a download.+ const ACTION_URL = "/FileAPI/file/resources/echo-content-escaped.py";++ const IFRAME_NAME = "formtargetframe";++ // Undoes the escapes from echo-content-escaped.py+ function unescape(str) {+ return str+ .replace(/\r\n?|\n/g, "\r\n")+ .replace(+ /\\x[0-9A-Fa-f]{2}/g,+ (escape) => String.fromCodePoint(parseInt(escape.substring(2), 16)),+ )+ .replace(/\\\\/g, "\\");+ }++ // Tests the form submission of an entry list containing a single entry.+ //+ // `expectedBuilder` is a function that takes in the actual form body+ // (necessary to get the multipart/form-data payload) and returns the form+ // body that should be expected.+ //+ // If `testFormData` is false, the form entry will be submitted in for+ // controls. If it is true, it will submitted by modifying the entry list+ // during the `formdata` event.+ async function formSubmissionTest({+ name,+ value,+ expectedBuilder,+ enctype,+ formEncoding,+ testFormData = false,+ testCase,+ }) {+ if (document.readyState !== "complete") {+ await new Promise((resolve) => addEventListener("load", resolve));+ }++ const formTargetFrame = Object.assign(document.createElement("iframe"), {+ name: IFRAME_NAME,+ });+ document.body.append(formTargetFrame);+ testCase.add_cleanup(() => {+ document.body.removeChild(formTargetFrame);+ });++ const form = Object.assign(document.createElement("form"), {+ acceptCharset: formEncoding,+ action: ACTION_URL,+ method: "POST",+ enctype,+ target: IFRAME_NAME,+ });+ document.body.append(form);+ testCase.add_cleanup(() => {+ document.body.removeChild(form);+ });++ if (!testFormData) {+ const input = document.createElement("input");+ input.name = name;+ if (value instanceof File) {+ input.type = "file";+ const dataTransfer = new DataTransfer();+ dataTransfer.items.add(value);+ input.files = dataTransfer.files;+ } else {+ input.type = "hidden";+ input.value = value;+ }+ form.append(input);+ } else {+ form.addEventListener("formdata", (evt) => {+ evt.formData.append(name, value);+ });+ }++ await new Promise((resolve) => {+ form.submit();+ formTargetFrame.onload = resolve;+ });++ const serialized = unescape(+ formTargetFrame.contentDocument.body.textContent,+ );+ const expected = expectedBuilder(serialized);+ assert_equals(serialized, expected);+ }++ // This function returns a function to add individual form tests corresponding+ // to some enctype.+ // `expectedBuilder` is an optional callback that takes two parameters:+ // `expected` (the `expected` property passed to a test) and `actualFormBody`+ // (the actual form body submitted by the browser, isomorphic-decoded). It+ // must return the correct form body that should have been submitted,+ // isomorphic-encoded. This is necessary in order to account for the+ // multipart/form-data boundary.+ //+ // The returned function takes an object with the following properties:+ // - `name`, the form entry's name. Must be a string.+ // - `value`, the form entry's value, either a string or a `File` object.+ // - `expected`, the expected form body. Usually a string, but it can be+ // anything depending on `expectedBuilder`.+ // - `formEncoding` (optional), the character encoding used for submitting the+ // form.+ // - `description`, used as part of the testharness test's description.+ window.formSubmissionTemplate = (+ enctype,+ expectedBuilder = (expected) => expected+ ) => {+ function form({+ name,+ value,+ expected,+ formEncoding = "utf-8",+ description,+ }) {+ const commonParams = {+ name,+ value,+ expectedBuilder: expectedBuilder.bind(null, expected),+ enctype,+ formEncoding,+ };++ // Normal form+ promise_test(+ (testCase) =>+ formSubmissionTest({+ ...commonParams,+ testCase,+ }),+ `${enctype}: ${description} (normal form)`,+ );++ // formdata event+ promise_test(+ (testCase) =>+ formSubmissionTest({+ ...commonParams,+ testFormData: true,+ testCase,+ }),+ `${enctype}: ${description} (formdata event)`,+ );+ }++ return form;+ };+})();diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.htmlnew file mode 100644index 00000000000..2c11492ce80--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src="enctypes-helper.js"></script>+<div id=log></div>+<script src="../../../../html/semantics/forms/form-submission-0/multipart-formdata.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.jsnew file mode 100644index 00000000000..ca69c7dac75--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/multipart-formdata.window.js@@ -0,0 +1,357 @@+// META: script=enctypes-helper.js++// Form submissions in multipart/form-data are also tested in+// /FileAPI/file/send-file*++// The `expected` property of objects passed to `formTest` must be an object+// with `name`, `value` and optionally `filename` properties, which represent+// the corresponding data in a multipart/form-data part.+const formTest = formSubmissionTemplate(+ "multipart/form-data",+ ({ name, filename, value }, serialized) => {+ let headers;+ if (filename === undefined) {+ headers = [`Content-Disposition: form-data; name="${name}"`];+ } else {+ headers = [+ `Content-Disposition: form-data; name="${name}"; filename="${filename}"`,+ "Content-Type: text/plain",+ ];+ }++ const boundary = serialized.split("\r\n")[0];++ return [+ boundary,+ ...headers,+ "",+ value,+ boundary + "--",+ "",+ ].join("\r\n");+ },+);++formTest({+ name: "basic",+ value: "test",+ expected: {+ name: "basic",+ value: "test",+ },+ description: "Basic test",+});++formTest({+ name: "basic",+ value: new File([], "file-test.txt", { type: "text/plain" }),+ expected: {+ name: "basic",+ filename: "file-test.txt",+ value: "",+ },+ description: "Basic File test",+});++formTest({+ name: "a\0b",+ value: "c",+ expected: {+ name: "a\0b",+ value: "c",+ },+ description: "0x00 in name",+});++formTest({+ name: "a",+ value: "b\0c",+ expected: {+ name: "a",+ value: "b\0c",+ },+ description: "0x00 in value",+});++formTest({+ name: "a",+ value: new File([], "b\0c", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b\0c",+ value: "",+ },+ description: "0x00 in filename",+});++formTest({+ name: "a\nb",+ value: "c",+ expected: {+ name: "a%0D%0Ab",+ value: "c",+ },+ description: "\\n in name",+});++formTest({+ name: "a\rb",+ value: "c",+ expected: {+ name: "a%0D%0Ab",+ value: "c",+ },+ description: "\\r in name",+});++formTest({+ name: "a\r\nb",+ value: "c",+ expected: {+ name: "a%0D%0Ab",+ value: "c",+ },+ description: "\\r\\n in name",+});++formTest({+ name: "a\n\rb",+ value: "c",+ expected: {+ name: "a%0D%0A%0D%0Ab",+ value: "c",+ },+ description: "\\n\\r in name",+});++formTest({+ name: "a",+ value: "b\nc",+ expected: {+ name: "a",+ value: "b\r\nc",+ },+ description: "\\n in value",+});++formTest({+ name: "a",+ value: "b\rc",+ expected: {+ name: "a",+ value: "b\r\nc",+ },+ description: "\\r in value",+});++formTest({+ name: "a",+ value: "b\r\nc",+ expected: {+ name: "a",+ value: "b\r\nc",+ },+ description: "\\r\\n in value",+});++formTest({+ name: "a",+ value: "b\n\rc",+ expected: {+ name: "a",+ value: "b\r\n\r\nc",+ },+ description: "\\n\\r in value",+});++formTest({+ name: "a",+ value: new File([], "b\nc", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b%0Ac",+ value: "",+ },+ description: "\\n in filename",+});++formTest({+ name: "a",+ value: new File([], "b\rc", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b%0Dc",+ value: "",+ },+ description: "\\r in filename",+});++formTest({+ name: "a",+ value: new File([], "b\r\nc", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b%0D%0Ac",+ value: "",+ },+ description: "\\r\\n in filename",+});++formTest({+ name: "a",+ value: new File([], "b\n\rc", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b%0A%0Dc",+ value: "",+ },+ description: "\\n\\r in filename",+});++formTest({+ name: 'a"b',+ value: "c",+ expected: {+ name: "a%22b",+ value: "c",+ },+ description: "double quote in name",+});++formTest({+ name: "a",+ value: 'b"c',+ expected: {+ name: "a",+ value: 'b"c',+ },+ description: "double quote in value",+});++formTest({+ name: "a",+ value: new File([], 'b"c', { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b%22c",+ value: "",+ },+ description: "double quote in filename",+});++formTest({+ name: "a'b",+ value: "c",+ expected: {+ name: "a'b",+ value: "c",+ },+ description: "single quote in name",+});++formTest({+ name: "a",+ value: "b'c",+ expected: {+ name: "a",+ value: "b'c",+ },+ description: "single quote in value",+});++formTest({+ name: "a",+ value: new File([], "b'c", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b'c",+ value: "",+ },+ description: "single quote in filename",+});++formTest({+ name: "a\\b",+ value: "c",+ expected: {+ name: "a\\b",+ value: "c",+ },+ description: "backslash in name",+});++formTest({+ name: "a",+ value: "b\\c",+ expected: {+ name: "a",+ value: "b\\c",+ },+ description: "backslash in value",+});++formTest({+ name: "a",+ value: new File([], "b\\c", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "b\\c",+ value: "",+ },+ description: "backslash in filename",+});++formTest({+ name: "áb",+ value: "ç",+ expected: {+ name: "\xC3\xA1b",+ value: "\xC3\xA7",+ },+ description: "non-ASCII in name and value",+});++formTest({+ name: "a",+ value: new File([], "ə.txt", { type: "text/plain" }),+ expected: {+ name: "a",+ filename: "\xC9\x99.txt",+ value: "",+ },+ description: "non-ASCII in filename",+});++formTest({+ name: "aəb",+ value: "c\uFFFDd",+ formEncoding: "windows-1252",+ expected: {+ name: "aəb",+ value: "c�d",+ },+ description: "characters not in encoding in name and value",+});++formTest({+ name: "á",+ value: new File([], "💩", { type: "text/plain" }),+ formEncoding: "windows-1252",+ expected: {+ name: "\xE1",+ filename: "💩",+ value: "",+ },+ description: "character not in encoding in filename",+});++formTest({+ name: "\uD800",+ value: "\uD800",+ formEncoding: "windows-1252",+ expected: {+ name: "�",+ value: "�"+ },+ description: "lone surrogate in name and value",+});diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.htmlnew file mode 100644index 00000000000..cdb07272c14--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src="enctypes-helper.js"></script>+<div id=log></div>+<script src="../../../../html/semantics/forms/form-submission-0/text-plain.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.jsnew file mode 100644index 00000000000..9ff77aed12f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/form-submission-0/text-plain.window.js@@ -0,0 +1,223 @@+// META: script=enctypes-helper.js++const formTest = formSubmissionTemplate("text/plain");++formTest({+ name: "basic",+ value: "test",+ expected: "basic=test\r\n",+ description: "Basic test",+});++formTest({+ name: "basic",+ value: new File([], "file-test.txt"),+ expected: "basic=file-test.txt\r\n",+ description: "Basic File test",+});++formTest({+ name: "a\0b",+ value: "c",+ expected: "a\0b=c\r\n",+ description: "0x00 in name",+});++formTest({+ name: "a",+ value: "b\0c",+ expected: "a=b\0c\r\n",+ description: "0x00 in value",+});++formTest({+ name: "a",+ value: new File([], "b\0c"),+ expected: "a=b\0c\r\n",+ description: "0x00 in filename",+});++formTest({+ name: "a\nb",+ value: "c",+ expected: "a\r\nb=c\r\n",+ description: "\\n in name",+});++formTest({+ name: "a\rb",+ value: "c",+ expected: "a\r\nb=c\r\n",+ description: "\\r in name",+});++formTest({+ name: "a\r\nb",+ value: "c",+ expected: "a\r\nb=c\r\n",+ description: "\\r\\n in name",+});++formTest({+ name: "a\n\rb",+ value: "c",+ expected: "a\r\n\r\nb=c\r\n",+ description: "\\n\\r in name",+});++formTest({+ name: "a",+ value: "b\nc",+ expected: "a=b\r\nc\r\n",+ description: "\\n in value",+});++formTest({+ name: "a",+ value: "b\rc",+ expected: "a=b\r\nc\r\n",+ description: "\\r in value",+});++formTest({+ name: "a",+ value: "b\r\nc",+ expected: "a=b\r\nc\r\n",+ description: "\\r\\n in value",+});++formTest({+ name: "a",+ value: "b\n\rc",+ expected: "a=b\r\n\r\nc\r\n",+ description: "\\n\\r in value",+});++formTest({+ name: "a",+ value: new File([], "b\nc"),+ expected: "a=b\r\nc\r\n",+ description: "\\n in filename",+});++formTest({+ name: "a",+ value: new File([], "b\rc"),+ expected: "a=b\r\nc\r\n",+ description: "\\r in filename",+});++formTest({+ name: "a",+ value: new File([], "b\r\nc"),+ expected: "a=b\r\nc\r\n",+ description: "\\r\\n in filename",+});++formTest({+ name: "a",+ value: new File([], "b\n\rc"),+ expected: "a=b\r\n\r\nc\r\n",+ description: "\\n\\r in filename",+});++formTest({+ name: 'a"b',+ value: "c",+ expected: 'a"b=c\r\n',+ description: "double quote in name",+});++formTest({+ name: "a",+ value: 'b"c',+ expected: 'a=b"c\r\n',+ description: "double quote in value",+});++formTest({+ name: "a",+ value: new File([], 'b"c'),+ expected: 'a=b"c\r\n',+ description: "double quote in filename",+});++formTest({+ name: "a'b",+ value: "c",+ expected: "a'b=c\r\n",+ description: "single quote in name",+});++formTest({+ name: "a",+ value: "b'c",+ expected: "a=b'c\r\n",+ description: "single quote in value",+});++formTest({+ name: "a",+ value: new File([], "b'c"),+ expected: "a=b'c\r\n",+ description: "single quote in filename",+});++formTest({+ name: "a\\b",+ value: "c",+ expected: "a\\b=c\r\n",+ description: "backslash in name",+});++formTest({+ name: "a",+ value: "b\\c",+ expected: "a=b\\c\r\n",+ description: "backslash in value",+});++formTest({+ name: "a",+ value: new File([], "b\\c"),+ expected: "a=b\\c\r\n",+ description: "backslash in filename",+});++formTest({+ name: "áb",+ value: "ç",+ expected: "\xC3\xA1b=\xC3\xA7\r\n",+ description: "non-ASCII in name and value",+});++formTest({+ name: "a",+ value: new File([], "ə.txt"),+ expected: "a=\xC9\x99.txt\r\n",+ description: "non-ASCII in filename",+});++formTest({+ name: "aəb",+ value: "c\uFFFDd",+ formEncoding: "windows-1252",+ expected: "aəb=c�d\r\n",+ description: "characters not in encoding in name and value",+});++formTest({+ name: "á",+ value: new File([], "💩"),+ formEncoding: "windows-1252",+ expected: "\xE1=💩\r\n",+ description: "character not in encoding in filename",+});++formTest({+ name: "\uD800",+ value: "\uD800",+ formEncoding: "windows-1252",+ expected: "�=�\r\n",+ description: "lone surrogate in name and value",+});