Skip to content

fix(endpoint-syndicate): call Array.isArray when wrapping a single target - #895

Merged
paulrobertlloyd merged 1 commit into
getindiekit:mainfrom
rmdes:fix/syndicate-single-target
Aug 22, 2026
Merged

paulrobertlloyd merged 1 commit into
getindiekit:mainfrom
rmdes:fix/syndicate-single-target

Conversation

@rmdes

@rmdes rmdes commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #894.

-  const syndicateToUrls = Array.isArray ? syndicateTo : [syndicateTo];
+  const syndicateToUrls = Array.isArray(syndicateTo)
+    ? syndicateTo
+    : [syndicateTo];

Array.isArray was referenced rather than called, so the condition was always truthy and the wrapping branch unreachable. A single syndication target reaches syndicateToTargets as a string — mf2 to JF2 conversion collapses a single-item array — the loop iterated its characters, and new URL("h") threw TypeError [ERR_INVALID_URL], propagating out of the loop's try and returning 500 from POST /syndicate.

Test

One unit test in test/unit/utils.js covering the string case. It fails on main with TypeError: Invalid URL and passes with this change.

I put it there rather than in an integration test because it needs no database: node --test test/unit/utils.js gives 7 passing. For the package as a whole: 24 tests, 24 passing; 23/23 on main before this change.

…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
@paulrobertlloyd
paulrobertlloyd merged commit 3a2b7cf into getindiekit:main Aug 22, 2026
1 check failed
@paulrobertlloyd

Copy link
Copy Markdown
Collaborator

Eek! Thanks for finding and fixing this @rmdes!

@rmdes

rmdes commented Aug 22, 2026

Copy link
Copy Markdown
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 :)

@paulrobertlloyd paulrobertlloyd added the plugin-endpoint Endpoint plug-in label Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin-endpoint Endpoint plug-in

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syndicating to a single target throws TypeError: Invalid URL (Array.isArray referenced, not called)

2 participants