mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(server): handle =
in cookie values correctly (#11613)
This commit is contained in:
parent
5a061c528c
commit
872a4be752
@ -517,7 +517,21 @@ function toHeadersArray(rawHeaders: string[]): types.HeadersArray {
|
||||
const redirectStatus = [301, 302, 303, 307, 308];
|
||||
|
||||
function parseCookie(header: string): types.NetworkCookie | null {
|
||||
const pairs = header.split(';').filter(s => s.trim().length > 0).map(p => p.split('=').map(s => s.trim()));
|
||||
const pairs = header.split(';').filter(s => s.trim().length > 0).map(p => {
|
||||
let key = '';
|
||||
let value = '';
|
||||
const separatorPos = p.indexOf('=');
|
||||
if (separatorPos === -1) {
|
||||
// If only a key is specified, the value is left undefined.
|
||||
key = p.trim();
|
||||
} else {
|
||||
// Otherwise we assume that the key is the element before the first `=`
|
||||
key = p.slice(0, separatorPos).trim();
|
||||
// And the value is the rest of the string.
|
||||
value = p.slice(separatorPos + 1).trim();
|
||||
}
|
||||
return [key, value];
|
||||
});
|
||||
if (!pairs.length)
|
||||
return null;
|
||||
const [name, value] = pairs[0];
|
||||
|
@ -166,6 +166,33 @@ it('should remove expired cookies', async ({ request, server }) => {
|
||||
expect(serverRequest.headers.cookie).toBe('a=v');
|
||||
});
|
||||
|
||||
it('should store cookie from Set-Cookie header even if it contains equal signs', async ({ request, server }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/11612' });
|
||||
|
||||
server.setRoute('/setcookie.html', (req, res) => {
|
||||
res.setHeader('Set-Cookie', ['f=value == value=; secure; httpOnly; path=/some=value']);
|
||||
res.end();
|
||||
});
|
||||
|
||||
await request.get(`http://a.b.one.com:${server.PORT}/setcookie.html`);
|
||||
const state = await request.storageState();
|
||||
expect(state).toEqual({
|
||||
'cookies': [
|
||||
{
|
||||
domain: 'a.b.one.com',
|
||||
expires: -1,
|
||||
name: 'f',
|
||||
path: '/some=value',
|
||||
sameSite: 'Lax',
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
value: 'value == value=',
|
||||
}
|
||||
],
|
||||
'origins': []
|
||||
});
|
||||
});
|
||||
|
||||
it('should export cookies to storage state', async ({ request, server }) => {
|
||||
const expires = new Date('12/31/2100 PST');
|
||||
server.setRoute('/setcookie.html', (req, res) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user