value.html (5397B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset=utf-8> 5 <title>Test cookie value 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 // TODO: there is more to test here, these tests capture the old 18 // ported http-state tests. Feel free to delete this comment when more 19 // are added, or these are split up into logical groups. 20 const valueTests = [ 21 { 22 cookie: "test=1, baz=qux", 23 expected: "test=1, baz=qux", 24 name: "Set value containing a comma", 25 }, 26 { 27 cookie: 'test="2, baz=qux"', 28 expected: 'test="2, baz=qux"', 29 name: "Set quoted value containing a comma", 30 }, 31 { 32 cookie: 'test="3zz;pp" ; ;', 33 expected: 'test="3zz', 34 name: "Ignore values after semicolon", 35 }, 36 { 37 cookie: 'test="4zz ;', 38 expected: 'test="4zz', 39 name: "Ignore whitespace at the end of value", 40 }, 41 { 42 cookie: 'test="5zzz " "ppp" ;', 43 expected: 'test="5zzz " "ppp"', 44 name: "Set value including quotes and whitespace up until semicolon", 45 }, 46 { 47 cookie: 'test=6A"B ;', 48 expected: 'test=6A"B', 49 name: "Set value with a single quote excluding whitespace" 50 }, 51 { 52 cookie: "test7", 53 expected: "test7", 54 name: "Set nameless cookie to its value", 55 }, 56 { 57 cookie: '"test8\"HHH"', 58 expected: '"test8\"HHH"', 59 name: "Set nameless cookie to its value with an escaped quote", 60 }, 61 { 62 cookie: 'test="9', 63 expected: 'test="9', 64 name: "Set value with unbalanced leading quote", 65 }, 66 { 67 cookie: "=test10", 68 expected: "test10", 69 name: "Set nameless cookie followed by '=' to its value", 70 }, 71 { 72 // 4 + 2 + 4090 = 4096 73 cookie: `test=11${"a".repeat(4090)}`, 74 expected: `test=11${"a".repeat(4090)}`, 75 name: "Set cookie with large name + value ( = 4kb)", 76 }, 77 { 78 // 4 + 2 + 4091 = 4097 79 cookie: `test=12${"a".repeat(4091)}`, 80 expected: "", 81 name: "Ignore cookie with large name + value ( > 4kb)", 82 }, 83 { 84 cookie: `test=13\nZYX`, 85 expected: "test=13", 86 name: "Set cookie but ignore value after LF", 87 }, 88 { 89 cookie: 'test="14 " ;', 90 expected: 'test="14 "', 91 name: "Set cookie ignoring whitespace after value endquote", 92 }, 93 { 94 cookie: "test=15 ;", 95 expected: "test=15", 96 name: "Ignore whitespace and ; after value", 97 }, 98 { 99 cookie: "test= 16", 100 expected: "test=16", 101 name: "Ignore whitespace preceding value", 102 }, 103 { 104 cookie: 'test="17"', 105 expected: 'test="17"', 106 name: "Set cookie with quotes in value", 107 }, 108 { 109 cookie: 'test=" 18 "', 110 expected: 'test=" 18 "', 111 name: "Set cookie keeping whitespace inside quoted value", 112 }, 113 { 114 cookie: 'test="19;wow"', 115 expected: 'test="19', 116 name: "Set cookie value ignoring characters after semicolon", 117 }, 118 { 119 cookie: 'test="20=20"', 120 expected: 'test="20=20"', 121 name: "Set cookie with another = inside quoted value", 122 }, 123 { 124 cookie: "test = 21 ; ttt", 125 expected: "test=21", 126 name: "Set cookie ignoring whitespace surrounding value and characters after first semicolon", 127 }, 128 { 129 cookie: ["testA=22", "test22=", "testB=22"], 130 expected: "testA=22; test22=; testB=22", 131 name: "Set valueless cookie, given `Set-Cookie: test22=`", 132 }, 133 { 134 cookie: "test=%32%33", 135 expected: "test=%32%33", 136 name: "URL-encoded cookie value is not decoded", 137 }, 138 { 139 cookie: "test24==", 140 expected: "test24==", 141 name: "Set cookie with value set to =", 142 }, 143 { 144 cookie: 'test=25=25', 145 expected: 'test=25=25', 146 name: "Set cookie with one = inside an unquoted value", 147 }, 148 { 149 cookie: 'test=26=26=26', 150 expected: 'test=26=26=26', 151 name: "Set cookie with two = inside an unquoted value", 152 }, 153 { 154 cookie: 'test=27 test', 155 expected: 'test=27 test', 156 name: "Set cookie with a space character in the value", 157 }, 158 { 159 cookie: ' test test28 ;', 160 expected: 'test test28', 161 name: "Set a nameless cookie with a space character in the value", 162 }, 163 ]; 164 165 for (const test of valueTests) { 166 httpCookieTest(test.cookie, test.expected, test.name, test.defaultPath); 167 } 168 </script> 169 </body> 170 </html>