unkey icon indicating copy to clipboard operation
unkey copied to clipboard

fix: trim spaces in strings for names

Open MichaelUnkey opened this issue 1 year ago • 5 comments

What does this PR do?

Added extra validation to stop names with only spaces.

Fixes # (issue) Eng-1518

Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] Chore (refactoring code, technical debt, workflow improvements)
  • [ ] Enhancement (small improvements)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

How should this be tested?

Validate changes do not cause issues for some reason.

Checklist

Required

  • [x] Filled out the "How to test" section in this PR
  • [x] Read Contributing Guide
  • [x] Self-reviewed my own code
  • [x] Commented on my code in hard-to-understand areas
  • [x] Ran pnpm build
  • [x] Ran pnpm fmt
  • [x] Checked for warnings, there are none
  • [x] Removed all console.logs
  • [x] Merged the latest changes from main onto my branch with git pull origin main
  • [x] My changes don't cause any responsiveness issues

Appreciated

  • [ ] If a UI change was made: Added a screen recording or screenshots to this PR
  • [ ] Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Enhanced input validation for various forms, ensuring that fields like name, ownerId, and identifier require a minimum length of 3 characters and cannot consist solely of whitespace.
    • Added regex validation for specific fields to enforce formatting rules, including alphanumeric characters, underscores, hyphens, and periods.
  • Bug Fixes

    • Improved validation logic to prevent submission of invalid or empty names across multiple components.
  • Documentation

    • Updated error messages to provide clearer feedback for validation failures.

MichaelUnkey avatar Oct 21 '24 17:10 MichaelUnkey

⚠️ No Changeset found

Latest commit: 8c4919095066dbbc5234ce596bc80805dedd9532

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Oct 21 '24 17:10 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 0:38am
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 0:38am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 0:38am
workflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 0:38am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 0:38am

vercel[bot] avatar Oct 21 '24 17:10 vercel[bot]

Thank you for following the naming conventions for pull request titles! 🙏

github-actions[bot] avatar Oct 21 '24 17:10 github-actions[bot]

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the validation logic across multiple components within the dashboard application. Key modifications include the introduction of trimming and minimum length requirements for various fields in form schemas, ensuring that inputs are not just whitespace and meet specified character limits. These changes apply to components such as UpdateKeyName, UpdateKeyOwnerId, CreateKey, UpdateApiName, and others, all aimed at improving input validation without altering the overall functionality or control flow of the components.

Changes

File Path Change Summary
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx Added refinement to name field to ensure it is a trimmed string if provided.
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx Updated ownerId field to include trimming and refinement for non-empty values.
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx Enhanced validation for prefix, ownerId, and name fields to ensure they are trimmed and not whitespace.
apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx Updated name field to require a minimum length of 3 characters and prevent whitespace-only submissions.
apps/dashboard/app/(app)/apis/create-api-button.tsx Increased name field minimum length from 2 to 3 characters and added trimming validation.
apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx Enhanced name field validation to require a minimum length of 3 characters and specific regex pattern.
apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx Updated identifier field to require a minimum length of 3 characters and added trimming validation.
apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx Updated name field to include regex validation for specific character requirements and length constraints.
apps/dashboard/app/new/create-api.tsx Modified name field validation to ensure it is a trimmed string with a minimum length of 3 characters.
apps/dashboard/app/new/create-workspace.tsx Enhanced name field validation to include trimming and length constraints of 3 to 50 characters.
apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx Updated name field validation to include trimming, regex pattern, and maximum length constraint of 50 characters.
apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx Modified name field validation to include trimming and existing constraints of minimum length and regex pattern.

Possibly related PRs

  • #2146: This PR modifies the CreateKey component in the same file as the main PR, specifically enhancing the form schema by adding a .trim() method to the name field, which aligns with the changes made in the main PR to improve validation logic for the name field.
  • #2253: Although primarily focused on fixing hydration warnings, this PR involves the RolesPage component, which may share similar validation logic or form handling practices as the UpdateKeyName component in the main PR, indicating a potential indirect relationship in terms of component structure and validation practices.
  • #2340: This PR addresses spacing issues in the changelog components, which may not directly relate to the validation changes in the main PR but indicates ongoing improvements in UI components that could be relevant in a broader context of user interface consistency across the application.

Suggested labels

Bug, 🕹️ oss.gg, :joystick: 150 points, hacktoberfest

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr

📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 97e255fcd2aa00c58a90d33130401d23f353c173 and 8c4919095066dbbc5234ce596bc80805dedd9532.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Oct 21 '24 17:10 coderabbitai[bot]