fix(endpoint-micropub): don't assume mp-syndicate-to is an array - #874
Merged
paulrobertlloyd merged 1 commit intoAug 16, 2026
Merged
Conversation
Converting mf2 to JF2 leaves this property in one of three shapes: an array when several targets are given, a string when one is, and an empty object when the client sends an empty array. Calling .includes on it directly threw TypeError: syndicateTo?.includes is not a function and failed the whole post. Any client that sends "mp-syndicate-to": [] hits it, which is what an unticked syndication list produces, so the post type made no difference — only whether the publication has syndication targets configured, since this returns early when it has none. Resolve the value to an array once before the loop, treating a string as a single target and anything else as no targets. That also makes the single-target case an exact comparison: it was previously a substring test against the string, which could match a uid that merely appeared inside another. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
I can confirm this issue exist on indiekit and my indiekit fork, and impact anyone using a micropub client and NOT selecting a syndication target when publishing a post. |
rmdes
added a commit
to rmdes/indiekit-endpoint-micropub
that referenced
this pull request
Aug 15, 2026
Posting failed with TypeError: syndicateTo?.includes is not a function for any client sending "mp-syndicate-to": [], which is what an unticked syndication list produces. Converting mf2 to JF2 leaves this property in one of three shapes: an array when several targets are given, a string when one is, and an empty object when the array is empty — and an object has no .includes. The post type made no difference; the only other condition is that the publication has syndication targets configured, since this returns early when it has none. That is why it looked intermittent: selecting a single target made the same post succeed. Resolve the value to an array once before the loop, treating a string as a single target and anything else as none. That also makes the single-target case an exact comparison rather than a substring test against the string. Same change proposed upstream in getindiekit/indiekit#874. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
rmdes
added a commit
to rmdes/indiekit-endpoint-micropub
that referenced
this pull request
Aug 15, 2026
Carries the mp-syndicate-to fix since beta.34: posting failed with "TypeError: syndicateTo?.includes is not a function" for any client sending "mp-syndicate-to": [], which is what an unticked syndication list produces. Converting mf2 to JF2 turns an empty array into an empty object, which has no .includes. Same change proposed upstream in getindiekit/indiekit#874. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
|
Good catch – thanks for the fix @rmdes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Posting fails with
whenever a client sends
"mp-syndicate-to": [].getSyndicateToPropertyreads the property straight off the JF2 object andcalls
.includeson it, but converting mf2 to JF2 leaves it in one of threeshapes:
.includes["a", "b"]["a", "b"]["a"]"a"[]{}An empty array is what an unticked syndication list produces, so this is
reachable through ordinary use rather than a malformed request. The post type
makes no difference; the only other condition is that the publication has
syndication targets configured, since the function returns early when it has
none. That combination is why it presents as intermittent — selecting a single
target makes the same post succeed.
Found from a browser extension that sent the property unconditionally. The
client has been fixed too, but any client can trip this and the failure takes
down post creation entirely.
Fix
Resolve the value to an array once, before the loop:
Anything that is neither an array nor a string is treated as no targets.
Behaviour change worth noting
The single-target case is now an exact comparison. It was previously
"https://example.website/".includes(uid)— a substring test — which wouldalso match a uid that merely appeared inside the configured target string.
Exact matching seems clearly right here, but it is a change.
Testing
packages/endpoint-micropub/test/unit/jf2.js, coveringthe non-array shapes and the string shape. I verified the first fails with
the original expression, reproducing the reported
TypeErrorexactly.endpoint-micropub;eslintandprettierclean.
identically on an untouched
main, so this changes nothing there.