feat: allow hyphens and underscores in space slugs#2136
Open
olivierlambert wants to merge 1 commit into
Open
Conversation
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
Contributor
Author
|
@Philipinho PR tested functionally with all the checkboxes ticked, it sounds pretty safe and useful to me 👍 |
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.
Summary
Closes #1712.
Currently space slugs are restricted to alphanumeric only. This means readable URLs like
sales-strategyare rejected and users have to fall back tosalesstrategy. This PR allows-and_inside the slug, while still requiring it to start and end with a letter or number.Changes
create-space.dto.ts): replace@IsAlphanumeric()with a@Matchesdecorator using regex^[a-zA-Z0-9]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$.create-space-form.tsx,edit-space-form.tsx): mirror the same regex in the Zod schemas and update the validation message.computeSpaceSluginlib/utils.tsx): preserve-/_in single-word names so typingsales-strategyproducessales-strategyinstead ofsales. Behavior for multi-word names (initials, e.g.Product Team→PT) is unchanged. Trailing/leading separators are stripped to keep the output valid.Validation rules (after this PR)
sales-strategysales_strategySales-Strategy-2024sa--les/sa__les-sales/sales-_sales/sales_sales(existing)Min length (2), max length (100), and the case-insensitive uniqueness constraint per workspace are unchanged.
Test plan
sales-strategy— succeedssales_strategy— succeeds-sales— rejected client-side and server-side-— succeeds, URL updatessales-strategyas the space name during creation — slug field auto-fills withsales-strategyProduct Teamas the space name — slug field auto-fills withPT(existing behavior preserved)