mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: postDataJSON with application/x-www-form-urlencoded; charset=UTF-8 (#29889)
Fixes https://github.com/microsoft/playwright/issues/29872
This commit is contained in:
parent
be325507cb
commit
38fc74db7c
@ -141,7 +141,7 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap
|
||||
return null;
|
||||
|
||||
const contentType = this.headers()['content-type'];
|
||||
if (contentType === 'application/x-www-form-urlencoded') {
|
||||
if (contentType.includes('application/x-www-form-urlencoded')) {
|
||||
const entries: Record<string, string> = {};
|
||||
const parsed = new URLSearchParams(postData);
|
||||
for (const [k, v] of parsed.entries())
|
||||
|
@ -290,6 +290,20 @@ it('should parse the data if content-type is application/x-www-form-urlencoded',
|
||||
expect(request.postDataJSON()).toEqual({ 'foo': 'bar', 'baz': '123' });
|
||||
});
|
||||
|
||||
it('should parse the data if content-type is application/x-www-form-urlencoded; charset=UTF-8', async ({ page, server }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29872' });
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const requestPromise = page.waitForRequest('**/post');
|
||||
await page.evaluate(() => fetch('./post', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
},
|
||||
body: 'foo=bar&baz=123'
|
||||
}));
|
||||
expect((await requestPromise).postDataJSON()).toEqual({ 'foo': 'bar', 'baz': '123' });
|
||||
});
|
||||
|
||||
it('should get |undefined| with postDataJSON() when there is no post data', async ({ page, server }) => {
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.request().postDataJSON()).toBe(null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user