microdotblog / microblog-react

MIT License
30 stars 3 forks source link

Micropub post request incorrectly sends array items in JSON body #92

Open paulrobertlloyd opened 2 months ago

paulrobertlloyd commented 2 months ago

In creating a post with 2 categories and 1 syndication target, using category and mp-syndicate-to which accept arrays, I see the following in the POST request:

{
  "h": "entry",
  "content": "Test.",
  "post-status": "published",
  "category[]": ["test", "testing"],
  "mp-destination": "https://indiekit-sandbox.netlify.app",
  "mp-syndicate-to[]": "https://mastodon.social/@indiekit_sandbox"
}

Note the array property keys include [], when they should not.

If I’m understanding this right, this might be confusing how application/json body is sent versus how the same information is sent using application/x-www-form-urlencoded.

An array should be provided in JSON as follows:

{
  "h": "entry",
  "content": "hello world",
  "category": ["foo", "bar"],
}

Only when form encoding arrays do multiple values get appended with [], meaning the above would be represented as:

h=entry&content=hello+world&category[]=foo&category[]=bar

This is as documented in the Micropub spec.

manton commented 1 month ago

Fixing this for the next beta. I had it on my list from a long time ago and somehow it never made it into a release.

manton commented 1 month ago

I'm testing this more and discovered that the Micro.blog app does not actually send as JSON. It's sending a content-type of "application/x-www-form-urlencoded" but actually the data looks like it's "multipart/form-data", which seems wrong. So maybe that's where the problem is? Anyway, it's definitely not JSON, I've confirmed this by logging the raw HTTP request.

paulrobertlloyd commented 1 month ago

Oh wait, this is a duplicate of #53. 🤦 I should have checked that I hadn’t already filled this issue. Any chance of this getting fixed in an upcoming release? The iOS app is now sooooo close to be the perfect iOS app for posting to a third-party Micropub server!