Skip to content

Commit afc90e1

Browse files
bakulfmoz-wptsync-bot
authored andcommitted
Update the CookieStore.set name/value validation algorithm
Differential Revision: https://phabricator.services.mozilla.com/D260066 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1981281 gecko-commit: e53c3ae42c6469c7029a50088675eb2142773e82 gecko-reviewers: valentin
1 parent 1b66856 commit afc90e1

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

cookiestore/cookieStore_set_arguments.https.any.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -390,26 +390,29 @@ promise_test(async testCase => {
390390
}, 'cookieStore.set with whitespace only name and value');
391391

392392
promise_test(async testCase => {
393-
testCase.add_cleanup(async () => {
394-
await cookieStore.delete('a b');
395-
});
396-
await cookieStore.set('a b', 'x y');
397-
const cookie = await cookieStore.get('a b');
398-
assert_equals(cookie.value, "x y");
399-
400-
await promise_rejects_js(testCase, TypeError, cookieStore.set(
401-
{ name: 'a ',
402-
value: 'x' }));
403-
404-
await promise_rejects_js(testCase, TypeError, cookieStore.set(
405-
{ name: ' a',
406-
value: 'x' }));
407-
408-
await promise_rejects_js(testCase, TypeError, cookieStore.set(
409-
{ name: 'a',
410-
value: 'x ' }));
393+
const tests = [
394+
{ set: ['a b', 'x y'], get: ['a b', 'x y'] },
395+
{ set: ['a ', 'x'], get: ['a', 'x'] },
396+
{ set: ['a\t', 'x'], get: ['a', 'x'] },
397+
{ set: [' a', 'x'], get: ['a', 'x'] },
398+
{ set: [' \t a', 'x'], get: ['a', 'x'] },
399+
{ set: [' \t a \t\t', 'x'], get: ['a', 'x'] },
400+
{ set: ['a', 'x '], get: ['a', 'x'] },
401+
{ set: ['a', 'x\t'], get: ['a', 'x'] },
402+
{ set: ['a', ' x'], get: ['a', 'x'] },
403+
{ set: ['a', ' \t x'], get: ['a', 'x'] },
404+
{ set: ['a', ' \t x \t\t'], get: ['a', 'x'] },
405+
];
406+
407+
for (const t of tests) {
408+
await cookieStore.set(t.set[0], t.set[1]);
409+
let cookie = await cookieStore.get(t.get[0]);
410+
assert_equals(cookie.value, t.get[1]);
411+
412+
await cookieStore.delete(t.get[0]);
413+
414+
cookie = await cookieStore.get(t.get[0]);
415+
assert_equals(cookie, null);
416+
}
411417

412-
await promise_rejects_js(testCase, TypeError, cookieStore.set(
413-
{ name: 'a',
414-
value: 'x ' }));
415418
}, 'cookieStore.set with whitespace at begining or end');

0 commit comments

Comments
 (0)