@@ -9,6 +9,13 @@ describe('Parse cookie', () => {
99 expect ( cookie [ 'tasty_cookie' ] ) . toBe ( 'strawberry' )
1010 } )
1111
12+ it ( 'Should trim only SP and HTAB around cookie pairs' , ( ) => {
13+ const cookieString = '\tyummy_cookie=choco;\t tasty_cookie = strawberry \t'
14+ const cookie : Cookie = parse ( cookieString )
15+ expect ( cookie [ 'yummy_cookie' ] ) . toBe ( 'choco' )
16+ expect ( cookie [ 'tasty_cookie' ] ) . toBe ( 'strawberry' )
17+ } )
18+
1219 it ( 'Should parse quoted cookie values' , ( ) => {
1320 const cookieString =
1421 'yummy_cookie="choco"; tasty_cookie = " strawberry " ; best_cookie="%20sugar%20";'
@@ -81,6 +88,19 @@ describe('Parse cookie', () => {
8188 expect ( cookie [ 'best_cookie\\' ] ) . toBeUndefined ( )
8289 } )
8390
91+ it ( 'Should ignore NBSP-prefixed cookie names when parsing one cookie by name' , ( ) => {
92+ const cookieString = '\u00a0dummy-cookie=evil; dummy-cookie=victim'
93+ const cookie : Cookie = parse ( cookieString , 'dummy-cookie' )
94+ expect ( cookie [ 'dummy-cookie' ] ) . toBe ( 'victim' )
95+ } )
96+
97+ it ( 'Should not collapse NBSP-prefixed cookie names when parsing all cookies' , ( ) => {
98+ const cookieString = 'dummy-cookie=victim; \u00a0dummy-cookie=evil'
99+ const cookie : Cookie = parse ( cookieString )
100+ expect ( cookie [ 'dummy-cookie' ] ) . toBe ( 'victim' )
101+ expect ( cookie [ '\u00a0dummy-cookie' ] ) . toBeUndefined ( )
102+ } )
103+
84104 it ( 'Should parse signed cookies' , async ( ) => {
85105 const secret = 'secret ingredient'
86106 const cookieString =
@@ -159,6 +179,14 @@ describe('Parse cookie', () => {
159179 expect ( cookie [ 'tasty_cookie' ] ) . toBe ( 'strawberry' )
160180 expect ( cookie [ 'great_cookie' ] ) . toBeUndefined ( )
161181 } )
182+
183+ it ( 'Should ignore NBSP-prefixed signed cookie names when parsing one cookie by name' , async ( ) => {
184+ const secret = 'secret ingredient'
185+ const cookieString =
186+ '\u00a0dummy-cookie=evil.UdFR2rBpS1GsHfGlUiYyMIdqxqwuEgplyQIgTJgpGWY%3D; dummy-cookie=choco.UdFR2rBpS1GsHfGlUiYyMIdqxqwuEgplyQIgTJgpGWY%3D'
187+ const cookie : SignedCookie = await parseSigned ( cookieString , secret , 'dummy-cookie' )
188+ expect ( cookie [ 'dummy-cookie' ] ) . toBe ( 'choco' )
189+ } )
162190} )
163191
164192describe ( 'Set cookie' , ( ) => {
0 commit comments