Fixes #27073.
This commit is contained in:
parent
476b74f7c4
commit
ed919f3dda
|
|
@ -223,7 +223,7 @@ export class HarTracer {
|
||||||
harEntry.response.cookies = this._options.omitCookies ? [] : event.cookies.map(c => {
|
harEntry.response.cookies = this._options.omitCookies ? [] : event.cookies.map(c => {
|
||||||
return {
|
return {
|
||||||
...c,
|
...c,
|
||||||
expires: c.expires === -1 ? undefined : new Date(c.expires).toISOString()
|
expires: c.expires === -1 ? undefined : safeDateToISOString(c.expires)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -658,11 +658,11 @@ function parseCookie(c: string): har.Cookie {
|
||||||
if (name === 'Domain')
|
if (name === 'Domain')
|
||||||
cookie.domain = value;
|
cookie.domain = value;
|
||||||
if (name === 'Expires')
|
if (name === 'Expires')
|
||||||
cookie.expires = new Date(value).toISOString();
|
cookie.expires = safeDateToISOString(value);
|
||||||
if (name === 'HttpOnly')
|
if (name === 'HttpOnly')
|
||||||
cookie.httpOnly = true;
|
cookie.httpOnly = true;
|
||||||
if (name === 'Max-Age')
|
if (name === 'Max-Age')
|
||||||
cookie.expires = new Date(Date.now() + (+value) * 1000).toISOString();
|
cookie.expires = safeDateToISOString(Date.now() + (+value) * 1000);
|
||||||
if (name === 'Path')
|
if (name === 'Path')
|
||||||
cookie.path = value;
|
cookie.path = value;
|
||||||
if (name === 'SameSite')
|
if (name === 'SameSite')
|
||||||
|
|
@ -673,4 +673,11 @@ function parseCookie(c: string): har.Cookie {
|
||||||
return cookie;
|
return cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeDateToISOString(value: string | number) {
|
||||||
|
try {
|
||||||
|
return new Date(value).toISOString();
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const startedDateSymbol = Symbol('startedDate');
|
const startedDateSymbol = Symbol('startedDate');
|
||||||
|
|
@ -226,6 +226,20 @@ it('should include set-cookies', async ({ contextFactory, server }, testInfo) =>
|
||||||
expect(new Date(cookies[2].expires).valueOf()).toBeGreaterThan(Date.now());
|
expect(new Date(cookies[2].expires).valueOf()).toBeGreaterThan(Date.now());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should skip invalid Expires', async ({ contextFactory, server }, testInfo) => {
|
||||||
|
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
||||||
|
server.setRoute('/empty.html', (req, res) => {
|
||||||
|
res.setHeader('Set-Cookie', [
|
||||||
|
'name=value;Expires=Sat Sep 14 01:02:27 CET 2024',
|
||||||
|
]);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
const log = await getLog();
|
||||||
|
const cookies = log.entries[0].response.cookies;
|
||||||
|
expect(cookies[0]).toEqual({ name: 'name', value: 'value' });
|
||||||
|
});
|
||||||
|
|
||||||
it('should include set-cookies with comma', async ({ contextFactory, server, browserName }, testInfo) => {
|
it('should include set-cookies with comma', async ({ contextFactory, server, browserName }, testInfo) => {
|
||||||
it.fixme(browserName === 'webkit', 'We get "name1=val, ue1, name2=val, ue2" as a header value');
|
it.fixme(browserName === 'webkit', 'We get "name1=val, ue1, name2=val, ue2" as a header value');
|
||||||
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue