Skip to content

Slug generation can return an empty string for non-Latin / punctuation-only names #41

Description

@chiptus

Problem

Slug generation drops every non-[a-z0-9] character. For a name with no ASCII alphanumerics — non-Latin artist/stage names (e.g. サカナクション, Чайф) or punctuation-only input — the slug collapses to an empty string "".

This is a pre-existing issue, but the schedule-ingestion PR (#31) makes it newly fatal: the new artists_slug_unique constraint means two artists that both slugify to "" collide hard, and an empty slug also breaks slug-based .single() lookups (e.g. useSetBySlug).

Affected code

The same logic is duplicated in three places and any fix must keep them consistent:

  • src/lib/slug.tsgenerateSlug
  • supabase/functions/diff-schedule/helpers.tstoSlug
  • supabase/migrations/20260509142022_commit_schedule_rpc.sqlcommit_schedule__slugify

Suggested fix

Guarantee a non-empty result. When the slug would be empty, fall back to a deterministic value derived from the original name (e.g. an md5(name)-based suffix/prefix) so the same name always produces the same slug across frontend, Edge, and SQL. Alternatively, broaden the allowed character set consistently in all three implementations.

Update — partial mitigation landed in #31

PR #31 now rejects artist/stage names with no [a-z0-9] at CSV parse time (parseScheduleCsv), with a clear message, so the empty-slug case can't reach the importer. This issue stays open for the proper cross-cutting fix (a guaranteed-non-empty slug) so other entry points — manual artist/stage creation — are covered too.

Related: distinct names colliding on one slug

Separate from empty slugs: two genuinely different names can slugify to the same value (e.g. "DJ Tennis" vs "DJ.Tennis"), silently linking them to one artist/stage. The same hash-fallback / disambiguation work should account for this case.

Context

Split out of PR #31 review (Copilot comments on helpers.ts toSlug and commit_schedule__slugify, plus the external review's slug-collision note). Deferred from that PR because the fix is cross-cutting and changes app-wide slug behavior beyond schedule import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions