|
1 | | -module('encoding', lifecycle); |
| 1 | +module('cookie-value encoding', lifecycle); |
2 | 2 |
|
3 | | -test('Handling quotes in the cookie value for read and write', function () { |
4 | | - expect(3); |
5 | | - |
6 | | - Cookies.set('quote', '"'); |
7 | | - strictEqual(Cookies.get('quote'), '"', 'should print the quote character'); |
8 | | - |
9 | | - Cookies.set('without-last', '"content'); |
10 | | - strictEqual(Cookies.get('without-last'), '"content', 'should print the quote character'); |
11 | | - |
12 | | - Cookies.set('without-first', 'content"'); |
13 | | - strictEqual(Cookies.get('without-first'), 'content"', 'should print the quote character'); |
| 3 | +test('cookie value with double quotes', function () { |
| 4 | + expect(1); |
| 5 | + Cookies.set('c', '"'); |
| 6 | + strictEqual(Cookies.get('c'), '"', 'should print the quote character'); |
14 | 7 | }); |
15 | 8 |
|
16 | | -test('RFC 6265 - reading cookie-octet enclosed in DQUOTE', function () { |
| 9 | +test('cookie value with double quotes in the left', function () { |
17 | 10 | expect(1); |
18 | | - document.cookie = 'c="v"'; |
19 | | - strictEqual(Cookies.get('c'), 'v', 'should decode the quotes'); |
| 11 | + Cookies.set('c', '"content'); |
| 12 | + strictEqual(Cookies.get('c'), '"content', 'should print the quote character'); |
20 | 13 | }); |
21 | 14 |
|
22 | | -test('RFC 6265 - unallowed characters in cookie value', function () { |
23 | | - expect(9); |
| 15 | +test('cookie value with double quotes in the right', function () { |
| 16 | + expect(1); |
| 17 | + Cookies.set('c', 'content"'); |
| 18 | + strictEqual(Cookies.get('c'), 'content"', 'should print the quote character'); |
| 19 | +}); |
24 | 20 |
|
25 | | - Cookies.set('whitespace', ' '); |
26 | | - strictEqual(Cookies.get('whitespace'), ' ', 'should handle the whitespace character'); |
27 | | - strictEqual(document.cookie, 'whitespace=%20', 'whitespace is not allowed, need to encode'); |
28 | | - Cookies.remove('whitespace'); |
| 21 | +test('RFC 6265 - character not allowed in the cookie value " "', function () { |
| 22 | + expect(2); |
| 23 | + Cookies.set('c', ' '); |
| 24 | + strictEqual(Cookies.get('c'), ' ', 'should handle the whitespace character'); |
| 25 | + strictEqual(document.cookie, 'c=%20', 'whitespace is not allowed, need to encode'); |
| 26 | +}); |
29 | 27 |
|
30 | | - Cookies.set('comma', ','); |
31 | | - strictEqual(Cookies.get('comma'), ',', 'should handle the comma character'); |
32 | | - strictEqual(document.cookie, 'comma=%2C', 'comma is not allowed, need to encode'); |
33 | | - Cookies.remove('comma'); |
| 28 | +test('RFC 6265 - character not allowed in the cookie value ","', function () { |
| 29 | + expect(2); |
| 30 | + Cookies.set('c', ','); |
| 31 | + strictEqual(Cookies.get('c'), ',', 'should handle the comma character'); |
| 32 | + strictEqual(document.cookie, 'c=%2C', 'comma is not allowed, need to encode'); |
| 33 | +}); |
34 | 34 |
|
35 | | - Cookies.set('semicolon', ';'); |
36 | | - strictEqual(Cookies.get('semicolon'), ';', 'should handle the semicolon character'); |
37 | | - strictEqual(document.cookie, 'semicolon=%3B', 'semicolon is not allowed, need to encode'); |
38 | | - Cookies.remove('semicolon'); |
| 35 | +test('RFC 6265 - character not allowed in the cookie value ";"', function () { |
| 36 | + expect(2); |
| 37 | + Cookies.set('c', ';'); |
| 38 | + strictEqual(Cookies.get('c'), ';', 'should handle the semicolon character'); |
| 39 | + strictEqual(document.cookie, 'c=%3B', 'semicolon is not allowed, need to encode'); |
| 40 | +}); |
39 | 41 |
|
40 | | - Cookies.set('backslash', '\\'); |
41 | | - strictEqual(Cookies.get('backslash'), '\\', 'should handle the backslash character'); |
42 | | - strictEqual(document.cookie, 'backslash=%5C', 'backslash is not allowed, need to encode'); |
43 | | - Cookies.remove('backslash'); |
| 42 | +test('RFC 6265 - character not allowed in the cookie value "\\"', function () { |
| 43 | + expect(2); |
| 44 | + Cookies.set('c', '\\'); |
| 45 | + strictEqual(Cookies.get('c'), '\\', 'should handle the backslash character'); |
| 46 | + strictEqual(document.cookie, 'c=%5C', 'backslash is not allowed, need to encode'); |
| 47 | +}); |
44 | 48 |
|
45 | | - Cookies.set('multiple', '" ,;\\" ,;\\'); |
46 | | - strictEqual(Cookies.get('multiple'), '" ,;\\" ,;\\', 'should handle multiple special characters'); |
47 | | - Cookies.remove('multiple'); |
| 49 | +test('RFC 6265 - characters not allowed in the cookie value should be replaced globally', function () { |
| 50 | + expect(2); |
| 51 | + Cookies.set('c', ';;'); |
| 52 | + strictEqual(Cookies.get('c'), ';;', 'should handle multiple not allowed characters'); |
| 53 | + strictEqual(document.cookie, 'c=%3B%3B', 'should replace multiple not allowed characters'); |
48 | 54 | }); |
49 | 55 |
|
50 | | -test('RFC 6265 - sharp is allowed in cookie value', function () { |
| 56 | +test('RFC 6265 - character allowed in the cookie value "#"', function () { |
51 | 57 | expect(2); |
52 | 58 | Cookies.set('c', '#'); |
53 | 59 | strictEqual(Cookies.get('c'), '#', 'should handle the sharp character'); |
54 | 60 | strictEqual(document.cookie, 'c=#', 'sharp is allowed, should not encode'); |
55 | 61 | }); |
56 | 62 |
|
57 | | -test('RFC 6265 - dollar sign is allowed in cookie value', function () { |
| 63 | +test('RFC 6265 - character allowed in the cookie value "$"', function () { |
58 | 64 | expect(2); |
59 | 65 | Cookies.set('c', '$'); |
60 | 66 | strictEqual(Cookies.get('c'), '$', 'should handle the dollar sign character'); |
61 | 67 | strictEqual(document.cookie, 'c=$', 'dollar sign is allowed, should not encode'); |
62 | 68 | }); |
63 | 69 |
|
64 | | -test('RFC 6265 - percent is allowed in cookie value', function () { |
| 70 | +test('RFC 6265 - character allowed in the cookie value "%"', function () { |
65 | 71 | expect(2); |
66 | 72 | Cookies.set('c', '%'); |
67 | 73 | strictEqual(Cookies.get('c'), '%', 'should handle the percent character'); |
68 | | - strictEqual(document.cookie, 'c=%25', 'percent is allowed, but encode to escape'); |
| 74 | + strictEqual(document.cookie, 'c=%25', 'percent is allowed, but need to be escaped'); |
69 | 75 | }); |
70 | 76 |
|
71 | | -test('RFC 6265 - ampersand is allowed in cookie value', function () { |
| 77 | +test('RFC 6265 - character allowed in the cookie value "&"', function () { |
72 | 78 | expect(2); |
73 | 79 | Cookies.set('c', '&'); |
74 | 80 | strictEqual(Cookies.get('c'), '&', 'should handle the ampersand character'); |
75 | 81 | strictEqual(document.cookie, 'c=&', 'ampersand is allowed, should not encode'); |
76 | 82 | }); |
77 | 83 |
|
78 | 84 | // github.com/carhartl/jquery-cookie/pull/62 |
79 | | -test('RFC 6265 - plus is allowed in cookie value', function () { |
| 85 | +test('RFC 6265 - character allowed in the cookie value "+"', function () { |
80 | 86 | expect(2); |
81 | 87 | Cookies.set('c', '+'); |
82 | 88 | strictEqual(Cookies.get('c'), '+', 'should handle the plus character'); |
83 | 89 | strictEqual(document.cookie, 'c=+', 'plus is allowed, should not encode'); |
84 | 90 | }); |
85 | 91 |
|
86 | | -test('RFC 6265 - colon is allowed in cookie value', function () { |
| 92 | +test('RFC 6265 - character allowed in the cookie value ":"', function () { |
87 | 93 | expect(2); |
88 | 94 | Cookies.set('c', ':'); |
89 | 95 | strictEqual(Cookies.get('c'), ':', 'should handle the colon character'); |
90 | 96 | strictEqual(document.cookie, 'c=:', 'colon is allowed, should not encode'); |
91 | 97 | }); |
92 | 98 |
|
93 | | -test('RFC 6265 - less-than is allowed in cookie value', function () { |
| 99 | +test('RFC 6265 - character allowed in the cookie value "<"', function () { |
94 | 100 | expect(2); |
95 | 101 | Cookies.set('c', '<'); |
96 | 102 | strictEqual(Cookies.get('c'), '<', 'should handle the less-than character'); |
97 | 103 | strictEqual(document.cookie, 'c=<', 'less-than is allowed, should not encode'); |
98 | 104 | }); |
99 | 105 |
|
100 | | -test('RFC 6265 - greater-than is allowed in cookie value', function () { |
| 106 | +test('RFC 6265 - character allowed in the cookie value ">"', function () { |
101 | 107 | expect(2); |
102 | 108 | Cookies.set('c', '>'); |
103 | 109 | strictEqual(Cookies.get('c'), '>', 'should handle the greater-than character'); |
104 | 110 | strictEqual(document.cookie, 'c=>', 'greater-than is allowed, should not encode'); |
105 | 111 | }); |
106 | 112 |
|
107 | | -test('RFC 6265 - equal sign is allowed in cookie value', function () { |
| 113 | +test('RFC 6265 - character allowed in the cookie value "="', function () { |
108 | 114 | expect(2); |
109 | 115 | Cookies.set('c', '='); |
110 | 116 | strictEqual(Cookies.get('c'), '=', 'should handle the equal sign character'); |
111 | 117 | strictEqual(document.cookie, 'c==', 'equal sign is allowed, should not encode'); |
112 | 118 | }); |
113 | 119 |
|
114 | | -test('RFC 6265 - slash is allowed in cookie value', function () { |
| 120 | +test('RFC 6265 - character allowed in the cookie value "/"', function () { |
115 | 121 | expect(2); |
116 | 122 | Cookies.set('c', '/'); |
117 | 123 | strictEqual(Cookies.get('c'), '/', 'should handle the slash character'); |
118 | 124 | strictEqual(document.cookie, 'c=/', 'slash is allowed, should not encode'); |
119 | 125 | }); |
120 | 126 |
|
121 | | -test('RFC 6265 - question mark is allowed in cookie value', function () { |
| 127 | +test('RFC 6265 - character allowed in the cookie value "?"', function () { |
122 | 128 | expect(2); |
123 | 129 | Cookies.set('c', '?'); |
124 | 130 | strictEqual(Cookies.get('c'), '?', 'should handle the question mark character'); |
125 | 131 | strictEqual(document.cookie, 'c=?', 'question mark is allowed, should not encode'); |
126 | 132 | }); |
127 | 133 |
|
128 | | -test('RFC 6265 - at is allowed in cookie value', function () { |
| 134 | +test('RFC 6265 - character allowed in the cookie value "@"', function () { |
129 | 135 | expect(2); |
130 | 136 | Cookies.set('c', '@'); |
131 | 137 | strictEqual(Cookies.get('c'), '@', 'should handle the at character'); |
132 | 138 | strictEqual(document.cookie, 'c=@', 'at is allowed, should not encode'); |
133 | 139 | }); |
134 | 140 |
|
135 | | -test('RFC 6265 - opening square bracket is allowed in cookie value', function () { |
| 141 | +test('RFC 6265 - character allowed in the cookie value "["', function () { |
136 | 142 | expect(2); |
137 | 143 | Cookies.set('c', '['); |
138 | 144 | strictEqual(Cookies.get('c'), '[', 'should handle the opening square bracket character'); |
139 | 145 | strictEqual(document.cookie, 'c=[', 'opening square bracket is allowed, should not encode'); |
140 | 146 | }); |
141 | 147 |
|
142 | | -test('RFC 6265 - closing square bracket is allowed in cookie value', function () { |
| 148 | +test('RFC 6265 - character allowed in the cookie value "]"', function () { |
143 | 149 | expect(2); |
144 | 150 | Cookies.set('c', ']'); |
145 | 151 | strictEqual(Cookies.get('c'), ']', 'should handle the closing square bracket character'); |
146 | 152 | strictEqual(document.cookie, 'c=]', 'closing square bracket is allowed, should not encode'); |
147 | 153 | }); |
148 | 154 |
|
149 | | -test('RFC 6265 - caret is allowed in cookie value', function () { |
| 155 | +test('RFC 6265 - character allowed in the cookie value "^"', function () { |
150 | 156 | expect(2); |
151 | 157 | Cookies.set('c', '^'); |
152 | 158 | strictEqual(Cookies.get('c'), '^', 'should handle the caret character'); |
153 | 159 | strictEqual(document.cookie, 'c=^', 'caret is allowed, should not encode'); |
154 | 160 | }); |
155 | 161 |
|
156 | | -test('RFC 6265 - grave accent is allowed in cookie value', function () { |
| 162 | +test('RFC 6265 - character allowed in the cookie value "`"', function () { |
157 | 163 | expect(2); |
158 | 164 | Cookies.set('c', '`'); |
159 | 165 | strictEqual(Cookies.get('c'), '`', 'should handle the grave accent character'); |
160 | 166 | strictEqual(document.cookie, 'c=`', 'grave accent is allowed, should not encode'); |
161 | 167 | }); |
162 | 168 |
|
163 | | -test('RFC 6265 - opening curly bracket is allowed in cookie value', function () { |
| 169 | +test('RFC 6265 - character allowed in the cookie value "{"', function () { |
164 | 170 | expect(2); |
165 | 171 | Cookies.set('c', '{'); |
166 | 172 | strictEqual(Cookies.get('c'), '{', 'should handle the opening curly bracket character'); |
167 | 173 | strictEqual(document.cookie, 'c={', 'opening curly bracket is allowed, should not encode'); |
168 | 174 | }); |
169 | 175 |
|
170 | | -test('RFC 6265 - closing curly bracket is allowed in cookie value', function () { |
| 176 | +test('RFC 6265 - character allowed in the cookie value "}"', function () { |
171 | 177 | expect(2); |
172 | 178 | Cookies.set('c', '}'); |
173 | 179 | strictEqual(Cookies.get('c'), '}', 'should handle the closing curly bracket character'); |
174 | 180 | strictEqual(document.cookie, 'c=}', 'closing curly bracket is allowed, should not encode'); |
175 | 181 | }); |
176 | 182 |
|
177 | | -test('RFC 6265 - pipe is allowed in cookie value', function () { |
| 183 | +test('RFC 6265 - character allowed in the cookie value "|"', function () { |
178 | 184 | expect(2); |
179 | 185 | Cookies.set('c', '|'); |
180 | 186 | strictEqual(Cookies.get('c'), '|', 'should handle the pipe character'); |
181 | 187 | strictEqual(document.cookie, 'c=|', 'pipe is allowed, should not encode'); |
182 | 188 | }); |
183 | 189 |
|
| 190 | +test('RFC 6265 - characters allowed in the cookie value should not be encoded globally', function () { |
| 191 | + expect(1); |
| 192 | + Cookies.set('c', '{{'); |
| 193 | + strictEqual(document.cookie, 'c={{', 'should not encode all the character occurrences'); |
| 194 | +}); |
| 195 | + |
| 196 | +module('cookie-name encoding', lifecycle); |
| 197 | + |
184 | 198 | test('RFC 6265 - unallowed characters in cookie-name', function () { |
185 | 199 | expect(38); |
186 | 200 |
|
|
0 commit comments