Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(fetch): json stringify string data when content-type has parameters (#43395)
Yury Semikhatsky39ce04859ac1
diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.tsindex 2915fa6dc5..c69f60a2e3 100644--- a/packages/playwright-core/src/client/fetch.ts+++ b/packages/playwright-core/src/client/fetch.ts@@ -462,7 +462,7 @@ function isJsonContentType(headers?: HeadersArray): boolean {return false;for (const { name, value } of headers) {if (name.toLocaleLowerCase() === 'content-type')- return value === 'application/json';+ return value.split(';')[0].trim().toLowerCase() === 'application/json';}return false;}diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.tsindex 2a714a4145..bfe1dfd507 100644--- a/tests/library/global-fetch.spec.ts+++ b/tests/library/global-fetch.spec.ts@@ -470,19 +470,23 @@ const serialization: [string, any][] = [];for (const [type, value] of serialization) {const stringifiedValue = JSON.stringify(value);- it(`should json stringify ${type} body when content-type is application/json`, async ({ playwright, server }) => {+ it(`should json stringify ${type} body when content-type is application/json`, {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43388' },+ }, async ({ playwright, server }) => {const request = await playwright.request.newContext();- const [req] = await Promise.all([- server.waitForRequest('/empty.html'),- request.post(server.EMPTY_PAGE, {- headers: {- 'content-type': 'application/json'- },- data: value- })- ]);- const body = await req.postBody;- expect(body.toString()).toEqual(stringifiedValue);+ for (const contentType of ['application/json', 'Application/JSON; charset=utf-8']) {+ const [req] = await Promise.all([+ server.waitForRequest('/empty.html'),+ request.post(server.EMPTY_PAGE, {+ headers: {+ 'content-type': contentType+ },+ data: value+ })+ ]);+ const body = await req.postBody;+ expect(body.toString()).toEqual(stringifiedValue);+ }await request.dispose();});