Skip to content

Commit 18d135f

Browse files
authored
Consistently trim whitespace from name and value
Also slowly start modernizing some algorithm conventions. Tests: web-platform-tests/wpt#54211. Fixes #276.
1 parent 6f3df44 commit 18d135f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

index.bs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ Per [[RFC6265BIS-14#name-storage-model|Cookies § Storage Model]], a [=cookie=]
404404

405405
</div>
406406

407+
<div algorithm>
408+
409+
To <dfn local-lt=normalize>normalize a cookie name or value</dfn> given a [=/string=] |input|:
410+
remove all U+0009 TAB and U+0020 SPACE that are at the start or end of |input|.
411+
412+
</div>
413+
407414
A cookie is <dfn>script-visible</dfn> when it is in-scope and its [=cookie/http-only-flag=] is unset. This is more formally enforced in the processing model, which consults [[RFC6265BIS-14#name-retrieval-model|Cookies § Retrieval Model]] at appropriate points.
408415

409416
A cookie is also subject to certain size limits. Per [[RFC6265BIS-14#name-storage-model|Cookies § Storage Model]]:
@@ -548,7 +555,7 @@ The <dfn method for=CookieStore>get(|options|)</dfn> method steps are:
548555
1. Run the following steps [=in parallel=]:
549556
1. Let |list| be the results of running [=query cookies=] with
550557
|url| and
551-
|options|["{{CookieStoreGetOptions/name}}"] (if present).
558+
|options|["{{CookieStoreGetOptions/name}}"] [=map/with default=] null.
552559
1. If |list| is failure, then [=reject=] |p| with a {{TypeError}} and abort these steps.
553560
1. If |list| [=list/is empty=], then [=/resolve=] |p| with null.
554561
1. Otherwise, [=/resolve=] |p| with the first item of |list|.
@@ -605,7 +612,7 @@ The <dfn method for=CookieStore>getAll(|options|)</dfn> method steps are:
605612
1. Run the following steps [=in parallel=]:
606613
1. Let |list| be the results of running [=query cookies=] with
607614
|url| and
608-
|options|["{{CookieStoreGetOptions/name}}"] (if present).
615+
|options|["{{CookieStoreGetOptions/name}}"] [=map/with default=] null.
609616
1. If |list| is failure, then [=reject=] |p| with a {{TypeError}}.
610617
1. Otherwise, [=/resolve=] |p| with |list|.
611618
1. Return |p|.
@@ -781,6 +788,7 @@ The <dfn method for=CookieStoreManager>subscribe(|subscriptions|)</dfn> method s
781788
1. Let |subscription list| be |registration|'s associated [=cookie change subscription list=].
782789
1. [=list/For each=] |entry| in |subscriptions|, run these steps:
783790
1. Let |name| be |entry|["{{CookieStoreGetOptions/name}}"].
791+
1. [=Normalize=] |name|.
784792
1. Let |url| be the result of [=basic URL parser|parsing=] |entry|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
785793
1. If |url| does not start with |registration|'s [=service worker registration/scope url=],
786794
then [=reject=] |p| with a {{TypeError}} and abort these steps.
@@ -837,6 +845,7 @@ The <dfn method for=CookieStoreManager>unsubscribe(|subscriptions|)</dfn> method
837845
1. Let |subscription list| be |registration|'s associated [=cookie change subscription list=].
838846
1. [=list/For each=] |entry| in |subscriptions|, run these steps:
839847
1. Let |name| be |entry|["{{CookieStoreGetOptions/name}}"].
848+
1. [=Normalize=] |name|.
840849
1. Let |url| be the result of [=basic URL parser|parsing=] |entry|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
841850
1. If |url| does not start with |registration|'s [=service worker registration/scope url=],
842851
then [=reject=] |p| with a {{TypeError}} and abort these steps.
@@ -1006,10 +1015,7 @@ and return a [=byte sequence=] corresponding to the closest `cookie-date` repres
10061015

10071016
<div algorithm>
10081017

1009-
To <dfn>query cookies</dfn> with
1010-
|url| and
1011-
optional |name|,
1012-
run the following steps:
1018+
To <dfn>query cookies</dfn> given a [=/URL=] |url| and [=/string=]-or-null |name|:
10131019

10141020
1. Perform the steps defined in [[RFC6265BIS-14#name-retrieval-model|Cookies § Retrieval Model]] to compute the "cookie-string from a given cookie store"
10151021
with |url| as <var ignore>request-uri</var>.
@@ -1020,7 +1026,8 @@ run the following steps:
10201026
1. Let |list| be a new [=/list=].
10211027
1. [=list/For each=] |cookie| in |cookie-list|, run these steps:
10221028
1. Assert: |cookie|'s [=cookie/http-only-flag=] is false.
1023-
1. If |name| is given, then run these steps:
1029+
1. If |name| is non-null:
1030+
1. [=Normalize=] |name|.
10241031
1. Let |cookieName| be the result of running [=UTF-8 decode without BOM=] on |cookie|'s [=cookie/name=].
10251032
1. If |cookieName| does not equal |name|,
10261033
then [=iteration/continue=].
@@ -1059,8 +1066,8 @@ optional |expires|,
10591066
|partitioned|
10601067
run the following steps:
10611068

1062-
1. Remove all U+0009 TAB and U+0020 SPACE that are at the start or end of |name|.
1063-
1. Remove all U+0009 TAB and U+0020 SPACE that are at the start or end of |value|.
1069+
1. [=Normalize=] |name|.
1070+
1. [=Normalize=] |value|.
10641071
1. If |name| or |value| contain U+003B (;), any [=C0 control=] character except U+0009 TAB, or U+007F DELETE, then return failure.
10651072

10661073
ISSUE(httpwg/http-extensions#1593): Note that it's up for discussion whether these character restrictions should also apply to |expires|, |domain|, |path|, and |sameSite| as well.
@@ -1138,6 +1145,8 @@ run the following steps:
11381145
Note: The exact value of |expires| is not important for the purposes of this algorithm,
11391146
as long as it is in the past.
11401147

1148+
1. [=Normalize=] |name|.
1149+
11411150
1. Let |value| be the empty string.
11421151

11431152
1. If |name|'s [=string/length=] is 0, then set |value| to any non-empty [=implementation-defined=] string.

0 commit comments

Comments
 (0)