Skip to content

feat: allow hyphens and underscores in space slugs#2136

Open
olivierlambert wants to merge 1 commit into
docmost:mainfrom
olivierlambert:feat/allow-hyphens-underscores-in-slugs
Open

feat: allow hyphens and underscores in space slugs#2136
olivierlambert wants to merge 1 commit into
docmost:mainfrom
olivierlambert:feat/allow-hyphens-underscores-in-slugs

Conversation

@olivierlambert
Copy link
Copy Markdown
Contributor

@olivierlambert olivierlambert commented Apr 28, 2026

Summary

Closes #1712.

Currently space slugs are restricted to alphanumeric only. This means readable URLs like sales-strategy are rejected and users have to fall back to salesstrategy. This PR allows - and _ inside the slug, while still requiring it to start and end with a letter or number.

Changes

  • Backend (create-space.dto.ts): replace @IsAlphanumeric() with a @Matches decorator using regex ^[a-zA-Z0-9]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$.
  • Frontend (create-space-form.tsx, edit-space-form.tsx): mirror the same regex in the Zod schemas and update the validation message.
  • Slug auto-generation (computeSpaceSlug in lib/utils.tsx): preserve -/_ in single-word names so typing sales-strategy produces sales-strategy instead of sales. Behavior for multi-word names (initials, e.g. Product TeamPT) is unchanged. Trailing/leading separators are stripped to keep the output valid.

Validation rules (after this PR)

Slug Result
sales-strategy accepted
sales_strategy accepted
Sales-Strategy-2024 accepted
sa--les / sa__les accepted
-sales / sales- rejected
_sales / sales_ rejected
sales (existing) accepted

Min length (2), max length (100), and the case-insensitive uniqueness constraint per workspace are unchanged.

Test plan

  • Create a new space with slug sales-strategy — succeeds
  • Create a new space with slug sales_strategy — succeeds
  • Create a new space with slug -sales — rejected client-side and server-side
  • Edit an existing space and change its slug to one containing - — succeeds, URL updates
  • Type sales-strategy as the space name during creation — slug field auto-fills with sales-strategy
  • Type Product Team as the space name — slug field auto-fills with PT (existing behavior preserved)

Loosens space slug validation to permit `-` and `_` characters
(but not as the first or last character). Updates the auto-generated
slug helper to preserve these characters when present in single-word
names (e.g. `sales-strategy` -> `sales-strategy` instead of `sales`).

Closes docmost#1712
@olivierlambert
Copy link
Copy Markdown
Contributor Author

@Philipinho PR tested functionally with all the checkboxes ticked, it sounds pretty safe and useful to me 👍

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.

Authorize slugs with - or _

1 participant