Skip to content

Properties with arrays are not provided correctly when posting to an external blog #53

@paulrobertlloyd

Description

@paulrobertlloyd

When posting to an external blog, the selected categories are sent to the Micropub server using an unrecognised key name, category[] instead of category.

This is the data sent to a server by the Micro.blog app:

{
  h: 'entry',
  content: 'Test categories',
  'category[]': [ 'indiekit', 'indieweb' ],
  'mp-destination': 'https://indiekit-sandbox.netlify.app'/,
}

However, sending the same data from another app (such as Quill) will send the following data:

{
  h: 'entry',
  content: 'Test categories',
  category: [ 'indiekit', 'indieweb' ],
}

It looks like the app appends categories to a category[] field:

params.append('category[]', category)

Using URLSearchParams.append() method multiple times adds the key value pair to a URL multiple times:

let url = new URL("https://website.example");
url.searchParams.append("category", "foo")
url.searchParams.append("category", "bar")
console.log("url", url)

// https://website.example/?category=foo&category=bar

Multiple params with the same key name get serialised as an Array, so there’s no need to indicate the field is an array by adding a [] suffix. That’s my understanding, anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions