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): include empty-string multipart fields in the request body (#41478)
Devin Rousso166a44017ccc
diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.tsindex f048bd2a36..3860effb56 100644--- a/packages/playwright-core/src/server/fetch.ts+++ b/packages/playwright-core/src/server/fetch.ts@@ -787,7 +787,7 @@ function serializePostData(params: channels.APIRequestContextFetchParams, headerfor (const field of params.multipartData) {if (field.file)formData.addFileField(field.name, field.file);- else if (field.value)+ else if (field.value !== undefined)formData.addField(field.name, field.value);}setHeader(headers, 'content-type', formData.contentTypeHeader(), true);diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.tsindex 0b755200a6..21405f2e82 100644--- a/tests/library/browsercontext-fetch.spec.ts+++ b/tests/library/browsercontext-fetch.spec.ts@@ -1047,6 +1047,7 @@ it('should support multipart/form-data', async function({ context, server }) {context.request.post(server.EMPTY_PAGE, {multipart: {firstName: 'John',+ middleName: '',lastName: 'Doe',file}@@ -1056,6 +1057,7 @@ it('should support multipart/form-data', async function({ context, server }) {expect(serverRequest.method).toBe('POST');expect(serverRequest.headers['content-type']).toContain('multipart/form-data');expect(fields['firstName']).toBe('John');+ expect(fields['middleName']).toBe('');expect(fields['lastName']).toBe('Doe');expect(files['file'].originalFilename).toBe(file.name);expect(files['file'].mimetype).toBe(file.mimeType);