fix(endpoint-syndicate): call Array.isArray when wrapping a single target - #895
Merged
paulrobertlloyd merged 1 commit intoAug 22, 2026
Merged
Conversation
…rget
`syndicateToTargets` normalises `mp-syndicate-to` to an array with:
const syndicateToUrls = Array.isArray ? syndicateTo : [syndicateTo];
`Array.isArray` is referenced but never called, so the condition is a function
reference and always truthy. The wrapping branch is unreachable and the value
is passed through unchanged.
Converting mf2 to JF2 collapses a single-item array to a string, so a post sent
to one syndication target arrives here as a string. `for (const url of
syndicateToUrls)` then iterates its characters, and `getSyndicationTarget` calls
`new URL("h")`, which throws:
TypeError [ERR_INVALID_URL]: Invalid URL
That call sits outside the try block in the loop, so the error propagates and
`POST /syndicate` returns 500 instead of syndicating. Two or more targets are
unaffected, since the value is already an array.
Adds a unit test covering the string case, which fails without this change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGHR7MuyvBaDbAFfAGUxeT
Collaborator
|
Eek! Thanks for finding and fixing this @rmdes! |
Collaborator
Author
|
I'm just really happy things I have faced while playing with this for rmendes.net can benefit indiekit users as a whole :) |
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.
Fixes #894.
Array.isArraywas referenced rather than called, so the condition was always truthy and the wrapping branch unreachable. A single syndication target reachessyndicateToTargetsas a string — mf2 to JF2 conversion collapses a single-item array — the loop iterated its characters, andnew URL("h")threwTypeError [ERR_INVALID_URL], propagating out of the loop'stryand returning 500 fromPOST /syndicate.Test
One unit test in
test/unit/utils.jscovering the string case. It fails onmainwithTypeError: Invalid URLand passes with this change.I put it there rather than in an integration test because it needs no database:
node --test test/unit/utils.jsgives 7 passing. For the package as a whole: 24 tests, 24 passing; 23/23 onmainbefore this change.