Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP: Do not prepend a whitespace when encoding body as multipart form data #1033

Merged
merged 4 commits into from
Feb 13, 2024

Conversation

adamziel
Copy link
Collaborator

When Playground request handler is called with a key: value object as its body, that data is encoded as a multipart string:

await playground.request({
	url: `/wp-admin/import.php`,
	method: 'POST',
	body: { import: file },
});

However, the encodeAsMultipart() function prepended one newline too many at the beginning of each multipart section.

Most of Playground do not use the key: value notation and just pass the POST data as bytes, which is why the normal operating functions were preserved.

However, the importFile step relied on the key: value notation. Importing WXR involves submitting a form with a nonce. However, the nonce contained an extra whitespace and was rejected by WordPress. This PR ensures that extra whitespace isn't there.

Testing instructions

  • Ensure the CI tests pass

… data

When Playground request handler is called with a key: value object as
its body, that data is encoded as a multipart string:

```ts
await playground.request({
	url: `/wp-admin/import.php`,
	method: 'POST',
	body: { import: file },
});
```

However, the `encodeAsMultipart()` function prepended one newline too
many at the beginning of each multipart section.

Most of Playground do not use the `key: value` notation and just pass
the POST data as bytes, which is why the normal operating functions were
preserved.

However, the importFile step relied on the `key: value` notation.
Importing WXR involves submitting a form with a nonce. However, the
nonce contained an extra whitespace and was rejected by WordPress. This
PR ensures that extra whitespace isn't there.

 ## Testing instructions

* Ensure the CI tests pass
adamziel added a commit that referenced this pull request Feb 13, 2024
…rt file step

A follow up to #1033

I noticed the import file step won't throw clear error information so
this PR adds some. In addition, it sets the progress bar caption to
"Importing content"
adamziel added a commit that referenced this pull request Feb 13, 2024
…rt file step (#1034)

A follow up to
#1033

I noticed the import file step won't throw clear error information so
this PR adds some. In addition, it sets the progress bar caption to
"Importing content".
@adamziel adamziel merged commit ef1eb3f into trunk Feb 13, 2024
5 checks passed
@adamziel adamziel deleted the fix-import-step branch February 13, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant