name.html (5647B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset=utf-8> 5 <title>Test cookie name parsing</title> 6 <meta name=help href="https://tools.ietf.org/html/rfc6265#section-5.2"> 7 <meta name="timeout" content="long"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/resources/testdriver.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <script src="/cookies/resources/cookie-test.js"></script> 13 </head> 14 <body> 15 <div id=log></div> 16 <script> 17 const nameTests = [ 18 { 19 cookie: "test1=; path = /", 20 expected: "test1=", 21 name: "Set valueless cookie to its name with empty value", 22 defaultPath: false, 23 }, 24 { 25 cookie: "=test=2", 26 expected: "test=2", 27 name: "Set a nameless cookie (that has an = in its value)", 28 }, 29 { 30 cookie: "===test=2b", 31 expected: "==test=2b", 32 name: "Set a nameless cookie (that has multiple ='s in its value)", 33 }, 34 { 35 cookie: "=test2c", 36 expected: "test2c", 37 name: "Set a nameless cookie", 38 }, 39 { 40 cookie: "test =3", 41 expected: "test=3", 42 name: "Remove trailing WSP characters from the name string", 43 }, 44 { 45 cookie: " test=4", 46 expected: "test=4", 47 name: "Remove leading WSP characters from the name string", 48 }, 49 { 50 cookie: ['"test=5"=test', '"test=5'], 51 expected: '"test=5', 52 name: "Only return the new cookie (with the same name)", 53 }, 54 { 55 cookie: "test6;cool=dude", 56 expected: "test6", 57 name: "Ignore invalid attributes after nameless cookie", 58 }, 59 { 60 cookie: "$Version=1; test=7", 61 expected: "$Version=1", 62 name: "Ignore invalid attributes after valid name (that looks like Cookie2 Version attribute)", 63 }, 64 { 65 cookie: "test test=8", 66 expected: "test test=8", 67 name: "Set a cookie that has whitespace in its name", 68 }, 69 { 70 cookie: '"test9;test"=9', 71 expected: '"test9', 72 name: "Set a nameless cookie ignoring characters after first ;", 73 }, 74 { 75 cookie: '"test\"10;baz"=qux', 76 expected: '"test\"10', 77 name: "Set a nameless cookie ignoring characters after first ; (2)", 78 }, 79 { 80 cookie: ["=test=11", "test11"], 81 expected: "test11", 82 name: "Return the most recent nameless cookie", 83 }, 84 { 85 cookie: ["test11", "test11a"], 86 expected: "test11a", 87 name: "Return the most recent nameless cookie, without leading =", 88 }, 89 { 90 cookie: ["test11", "test11a", "=test11b"], 91 expected: "test11b", 92 name: "Return the most recent nameless cookie, even if preceded by =", 93 }, 94 { 95 cookie: ["test11", "test11a", "=test11b", "test=11c"], 96 expected: "test11b; test=11c", 97 name: "Return the most recent nameless cookie, even if preceded by =, in addition to other valid cookie", 98 }, 99 { 100 cookie: ["test12=11", "test12=12"], 101 expected: "test12=12", 102 name: "Use last value for cookies with identical names", 103 }, 104 { 105 cookie: ["testA=13", "testB=13"], 106 expected: "testA=13; testB=13", 107 name: "Keep first-in, first-out name order", 108 }, 109 { 110 cookie: ["a=test14", "z=test14"], 111 expected: "a=test14; z=test14", 112 name: "Keep first-in, first-out single-char name order", 113 }, 114 { 115 cookie: ["z=test15", "a=test15"], 116 expected: "z=test15; a=test15", 117 name: "Keep non-alphabetic first-in, first-out name order", 118 }, 119 { 120 cookie: "z=test16, a=test16", 121 expected: "z=test16, a=test16", 122 name: "Keep first-in, first-out order if comma-separated", 123 }, 124 { 125 cookie: ["testA=16", "=test16", "testB=16"], 126 expected: "testA=16; test16; testB=16", 127 name: "Set nameless cookie, given `Set-Cookie: =test16`", 128 }, 129 { 130 cookie: ["test17a", "test17b"], 131 expected: "test17b", 132 name: "Overwrite nameless cookie", 133 }, 134 { 135 cookie: ["=__Secure-abc=123", "=__Host-abc=123", "=__SeCuRe-abc=123", "=__HoSt-abc=123", "__Secure-abc", "__Host-abc", "__SeCuRe-abc", "__HoSt-abc"], 136 expected: "", 137 name: "Ignore nameless cookies that impersonate cookie prefixes", 138 }, 139 { 140 cookie: "=", 141 expected: "", 142 name: "Ignore cookie with empty name and empty value", 143 }, 144 { 145 cookie: "", 146 expected: "", 147 name: "Ignore cookie with no name or value", 148 }, 149 { 150 cookie: "%74%65%73%74=20", 151 expected: "%74%65%73%74=20", 152 name: "URL-encoded cookie name is not decoded", 153 }, 154 ]; 155 156 for (const test of nameTests) { 157 httpCookieTest(test.cookie, test.expected, test.name); 158 } 159 160 for (const name of ["a", "1", "$", "!a", "@a", "#a", "$a", "%a", 161 "^a", "&a", "*a", "(a", ")a", "-a", "_a", "+", 162 '"a', '"a=b"' 163 ]) { 164 const cookie = `${name}=test`; 165 httpCookieTest(cookie, cookie, `Name is set as expected for ${name}=test`); 166 } 167 </script> 168 </body> 169 </html>