Skip to content

fix(topics): URL-safe topic slugs so /topics/<slug> serves (#2099 follow-up) - #2106

Merged
jung-thomas merged 1 commit into
DEVfrom
fix/topic-slug-urlsafe
Sep 2, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
fix/topic-slug-urlsafe

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Problem

All 152 published topic-<slug> BLOBs 404 on DEV /topics/<slug>, even though publish wrote them (verified via /content/hashes). Root cause: flattenTopicSlug only did .replace(/--/g,'-').toLowerCase(), leaving the spaces, colons and slashes that real Tags.titlePath values carry (e.g. software product : technology platform / … / open connectors). /content/topics/:slug delegates to serveHandler, whose VALID_SLUG = /^[a-z0-9][a-z0-9-]*$/ rejects those chars → every topic slug 404s. Concepts work because their slugs are already hyphen-only.

Unit tests passed pre-merge because they used synthetic >/-- titlePaths (clean); prod titlePaths are dirty.

Empirically confirmed on DEV SRV: 0 of 152 stored topic slugs pass VALID_SLUG.

Fix

  • Add slugifyTopic(): fold every non-[a-z0-9] run to a single hyphen, trim. flattenTopicSlug delegates to it (subsumes the old -- collapse).
  • buildTopicSlugMap slugifies the facet for collision qualification and never emits a leading-hyphen slug when a facetless titlePath collides.
  • New unit tests assert real-world dirty titlePaths yield VALID_SLUG-safe slugs; existing collision/normalize tests still pass.

Tree hrefs, stored topic-* keys, and resolveTopicBySlug all derive from buildTopicSlugMap, so the fix propagates uniformly. Tree segment labels stay human-readable (display only).

Deploy note

Requires a full content republish after the fixed backend deploys — render-topics and the tree render server-side, so stored topic-* keys only become URL-safe once this code is live. Column width already proven (current dirty keys are similar length).

Test plan

  • test/unit/topic-slug.test.js + topics-query.test.js (18 topic tests green)
  • Post-deploy: republish DEV (full) → /topics/<leaf>/ returns 200; topics-route smoke flips 404→200

…low-up)

flattenTopicSlug only collapsed '--'->'-' and lowercased, leaving the
spaces, colons and slashes that real Tags.titlePath values carry. Every
generated topic slug therefore failed serveHandler's VALID_SLUG guard
(/^[a-z0-9][a-z0-9-]*/), so all 152 published topic-<slug> BLOBs 404'd
on /topics/<slug> while the tree/index still linked to them.

- Add slugifyTopic(): fold every non-[a-z0-9] run to a single hyphen, trim.
- flattenTopicSlug delegates to it (subsumes the old '--' collapse).
- buildTopicSlugMap slugifies the facet for collision qualification and
  never emits a leading-hyphen slug when a facetless titlePath collides.
- Unit tests assert real-world dirty titlePaths yield VALID_SLUG-safe slugs.

Requires a full content republish so stored topic-* keys match the new
slugs (render-topics renders server-side).
@jung-thomas
jung-thomas merged commit 46da520 into DEV Sep 2, 2026
3 of 4 checks passed
@jung-thomas
jung-thomas deleted the fix/topic-slug-urlsafe branch September 2, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant