summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/form-submission-0/newline-normalization.html
blob: 2c83c5a1e9a07c02f4443bfd96b0a15411a5f288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>
      Constructing the entry list shouldn't perform newline normalization
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <script>
      function createForm(testCase, name, value) {
        const form = document.createElement("form");
        const input = document.createElement("input");
        input.type = "hidden";
        input.name = name;
        input.value = value;
        form.appendChild(input);
        document.body.appendChild(form);
        testCase.add_cleanup(() => {
          document.body.removeChild(form);
        });
        return form;
      }

      function createFormWithFile(testCase, name, filename) {
        const form = document.createElement("form");
        const input = document.createElement("input");
        input.type = "file";
        input.name = name;
        const dataTransfer = new DataTransfer();
        dataTransfer.items.add(new File([], filename, { type: "text/plain" }));
        input.files = dataTransfer.files;
        form.appendChild(input);
        document.body.appendChild(form);
        testCase.add_cleanup(() => {
          document.body.removeChild(form);
        });
        return form;
      }

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a", "b\nc"));
        assert_equals(formData.get("a"), "b\nc");
      }, document.title + ": \\n in the value");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a", "b\rc"));
        assert_equals(formData.get("a"), "b\rc");
      }, document.title + ": \\r in the value");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a", "b\r\nc"));
        assert_equals(formData.get("a"), "b\r\nc");
      }, document.title + ": \\r\\n in the value");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a", "b\n\rc"));
        assert_equals(formData.get("a"), "b\n\rc");
      }, document.title + ": \\n\\r in the value");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a\nb", "c"));
        assert_equals([...formData][0][0], "a\nb");
      }, document.title + ": \\n in the name");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a\rb", "c"));
        assert_equals([...formData][0][0], "a\rb");
      }, document.title + ": \\r in the name");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a\r\nb", "c"));
        assert_equals([...formData][0][0], "a\r\nb");
      }, document.title + ": \\r\\n in the name");

      test((testCase) => {
        const formData = new FormData(createForm(testCase, "a\n\rb", "c"));
        assert_equals([...formData][0][0], "a\n\rb");
      }, document.title + ": \\n\\r in the name");

      test((testCase) => {
        const formData = new FormData(
          createFormWithFile(testCase, "a", "b\nc")
        );
        assert_equals(formData.get("a").name, "b\nc");
      }, document.title + ": \\n in the filename");

      test((testCase) => {
        const formData = new FormData(
          createFormWithFile(testCase, "a", "b\rc")
        );
        assert_equals(formData.get("a").name, "b\rc");
      }, document.title + ": \\r in the filename");

      test((testCase) => {
        const formData = new FormData(
          createFormWithFile(testCase, "a", "b\r\nc")
        );
        assert_equals(formData.get("a").name, "b\r\nc");
      }, document.title + ": \\r\\n in the filename");

      test((testCase) => {
        const formData = new FormData(
          createFormWithFile(testCase, "a", "b\n\rc")
        );
        assert_equals(formData.get("a").name, "b\n\rc");
      }, document.title + ": \\n\\r in the filename");
    </script>
  </body>
</html>