Skip to content

Feature: Normalize project name input and sanitize whitespace - #117

Merged
fehranbit merged 3 commits into
mainfrom
feat/project-name-normalization
Dec 5, 2025
Merged

fehranbit merged 3 commits into
mainfrom
feat/project-name-normalization

Conversation

@erik-arne

@erik-arne erik-arne commented Dec 5, 2025 •

Copy link
Copy Markdown
Collaborator

This change improves the user experience for project creation by normalizing project names and sanitizing input.

Changes:

  • Implemented basic input sanitization to remove leading/trailing whitespace from project names.
  • Added name normalization within src/actions/projects/createProject/action.ts to prevent accidental duplicate names due to varied spacing.
  • Ensures more consistent and cleaner data entry for project names.

Summary by CodeRabbit

  • Bug Fixes
    • Improved project title handling: consecutive whitespace is normalized to single spaces and titles are trimmed for create and update flows. Length constraints are enforced, and validation messages will prevent empty or overly long titles, ensuring consistent formatting and more reliable input validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 5, 2025 •

Copy link
Copy Markdown

Walkthrough

Both project schemas now normalize the title by trimming and collapsing consecutive whitespace into single spaces before applying existing min/max length validation; no other fields changed.

Changes

Cohort / File(s) Summary
Schema whitespace normalization
src/actions/projects/createProject/schema.ts, src/actions/projects/updateProject/schema.ts
title now normalizes whitespace: trimming and collapsing consecutive whitespace into single spaces via a transform, with existing min/max length validations and messages retained.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Small, consistent change across two schema files.
  • Areas to check:
    • Transformation order (trim then collapse) is intentional.
    • Validation messages and inferred types remain unchanged.
    • Confirm no downstream code depends on original unnormalized spacing.

Possibly related PRs

Suggested reviewers

  • fehranbit

Poem

I nibble gaps and stitch them tight,
I fold loose spaces till they’re right,
One tidy title, calm and spare,
A single space now rests there —
Rabbit-approved, with hopping delight 🐰✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: normalizing project names and sanitizing whitespace in input validation schemas.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/project-name-normalization

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c224ca8 and a14db1f.

📒 Files selected for processing (1)
  • src/actions/projects/updateProject/schema.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/actions/projects/updateProject/schema.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d399acb and 724cf1c.

📒 Files selected for processing (1)
  • src/actions/projects/createProject/schema.ts (1 hunks)


export const createProjectSchema = z.object({
title: z.string().trim().min(1, { message: 'Title is required' }).max(200, { message: 'Title is too long' }),
title: z.string().trim().transform((val) => val.replace(/\s+/g, ' ')).min(1, { message: 'Title is required' }).max(200, { message: 'Title is too long' }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "schema.prisma" -o -name "*.prisma" | head -20

Repository: Authormaton/authormaton

Length of output: 89


🏁 Script executed:

cat -n ./prisma/schema.prisma

Repository: Authormaton/authormaton

Length of output: 2254


🏁 Script executed:

find . -path ./node_modules -prune -o -name "*migration*" -type f -print | grep -i prisma

Repository: Authormaton/authormaton

Length of output: 292


🏁 Script executed:

cat -n ./prisma/migrations/20250909132930_added_projects/migration.sql

Repository: Authormaton/authormaton

Length of output: 797


🏁 Script executed:

ls -la ./prisma/migrations/

Repository: Authormaton/authormaton

Length of output: 471


🏁 Script executed:

cat -n ./prisma/migrations/20250917091926_required_user_name/migration.sql

Repository: Authormaton/authormaton

Length of output: 343


🏁 Script executed:

cd ./prisma && prisma migrate status 2>&1 || echo "Prisma CLI check completed"

Repository: Authormaton/authormaton

Length of output: 138


🏁 Script executed:

rg -n "createProject" --type ts -g "!*.test.ts" -B 2 -A 5

Repository: Authormaton/authormaton

Length of output: 5228


🏁 Script executed:

cat -n src/actions/projects/createProject/logic.ts

Repository: Authormaton/authormaton

Length of output: 1940


🏁 Script executed:

rg -n "@@unique" src/

Repository: Authormaton/authormaton

Length of output: 49


🏁 Script executed:

rg -n "project\." src/ --type ts -C 2 | grep -i "title\|findUnique\|where" | head -40

Repository: Authormaton/authormaton

Length of output: 855


🏁 Script executed:

cat -n src/actions/projects/updateProject/schema.ts

Repository: Authormaton/authormaton

Length of output: 307


🏁 Script executed:

cat -n src/actions/projects/updateProject/logic.ts

Repository: Authormaton/authormaton

Length of output: 673


🏁 Script executed:

cat -n src/actions/projects/getProjects.ts | head -60

Repository: Authormaton/authormaton

Length of output: 2002


Critical gaps prevent this change from functioning correctly.

The whitespace normalization logic is implemented correctly for new projects, but the change is incomplete and has critical issues:

  1. Missing database migration: The @@unique([userId, title]) constraint is defined in schema.prisma but not yet migrated. The P2002 error handling in createProject logic cannot work until the database enforces this constraint. This must be generated and applied before deployment.

  2. Update route bypasses validation: updateProject/schema.ts has no validation (title: z.string()), allowing users to bypass normalization by updating existing projects. Users could create "My Project" (normalized), then update it to "My Project", creating inconsistent data. Apply the same normalization and validation chain to updateProject schema.

  3. Data consistency risk: If the database constraint migration is applied to existing data containing duplicate titles that differ only in whitespace, the migration will fail. Review existing projects for duplicates before adding the constraint.

🤖 Prompt for AI Agents
In src/actions/projects/createProject/schema.ts around line 5, the title
normalization was added but three critical fixes are required: 1) generate and
apply a Prisma migration that enforces the @@unique([userId, title]) constraint
in schema.prisma before deploying so the P2002 handling in createProject will
work; 2) make updateProject/schema.ts use the identical
z.string().trim().transform(...).min(1).max(200) normalization/validation chain
so updates cannot bypass normalization; 3) before applying the migration, scan
existing projects for title duplicates that differ only by whitespace and
resolve them (merge/rename/delete) to avoid migration failure, then run the
migration and deploy.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 724cf1c and c224ca8.

📒 Files selected for processing (1)
  • src/actions/projects/updateProject/schema.ts (1 hunks)

Comment thread src/actions/projects/updateProject/schema.ts Outdated
@fehranbit

Copy link
Copy Markdown
Member

this'll make project name inputs way cleaner and prevent duplicates, nice work!

@fehranbit
fehranbit merged commit 8d27644 into main Dec 5, 2025
1 of 2 checks passed
@fehranbit
fehranbit deleted the feat/project-name-normalization branch December 5, 2025 18:24
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.

2 participants