Skip to content

Conversation

@Allan2000-Git
Copy link
Contributor

@Allan2000-Git Allan2000-Git commented Jul 1, 2025

User description

Description

This PR introduces a utility function validateAsciiInput to ensure input strings (workspace, project, secret, variable & environment names) contain only ASCII alphanumeric characters (A-Z, a-z, 0-9). It returns true for valid inputs and false otherwise.

Fixes #929

Test cases

Valid:
validateAsciiInput("Hello123")
validateAsciiInput("A1B2C3")
validateAsciiInput("abcDEF")
validateAsciiInput("1234567890")

Invalid:
validateAsciiInput("Hello World")
validateAsciiInput("abc@123")
validateAsciiInput("name#")
validateAsciiInput("💡idea")
validateAsciiInput("abc-def")
validateAsciiInput("abc_def")
validateAsciiInput("abc.123")

Dependencies

N/A

Future Improvements

N/A

Mentions

@rajdip-b

Screenshots of relevant screens

Screenshot 2025-07-01 at 11 50 25 PM
Screen.Recording.2025-07-01.at.11.21.28.PM.1.mov

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

PR Type

Bug fix, Enhancement


Description

  • Add ASCII validation for entity names (workspace, project, environment, secret, variable)

  • Prevent unicode characters causing slug generation issues

  • Display validation errors with red borders and messages

  • Disable form submission when validation fails


Changes diagram

flowchart LR
  A["User Input"] --> B["validateAsciiInput()"]
  B --> C{"ASCII Only?"}
  C -->|Yes| D["Enable Submit"]
  C -->|No| E["Show Error & Disable Submit"]
  E --> F["Red Border & Error Message"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
utils.ts
Add ASCII validation utility function                                       

apps/platform/src/lib/utils.ts

  • Add validateAsciiInput() function with alphanumeric regex validation
  • Returns boolean for ASCII-only string validation
  • +12/-0   
    Bug fix
    index.tsx
    Add environment name ASCII validation                                       

    apps/platform/src/components/dashboard/environment/addEnvironmentDialogue/index.tsx

  • Import validation utility and styling functions
  • Add environment name validation with error state
  • Display red border and error message for invalid input
  • Disable submit button when validation fails
  • +13/-4   
    index.tsx
    Add project name ASCII validation                                               

    apps/platform/src/components/dashboard/project/createProjectDialogue/index.tsx

  • Import validation utility and styling functions
  • Add project name validation with error state
  • Display red border and error message for invalid input
  • Disable submit button when validation fails
  • +27/-12 
    index.tsx
    Add secret name ASCII validation                                                 

    apps/platform/src/components/dashboard/secret/addSecretDialogue/index.tsx

  • Import validation utility and styling functions
  • Add secret name validation with error state
  • Display red border and error message for invalid input
  • Disable submit button when validation fails
  • +29/-15 
    index.tsx
    Add variable name ASCII validation                                             

    apps/platform/src/components/dashboard/variable/addVariableDialogue/index.tsx

  • Import validation utility and styling functions
  • Add variable name validation with error state
  • Display red border and error message for invalid input
  • Disable submit button when validation fails
  • +28/-14 
    add-workspace-dialog.tsx
    Add workspace name ASCII validation                                           

    apps/platform/src/components/shared/add-workspace-dialog.tsx

  • Import validation utility and styling functions
  • Add workspace name validation with error state
  • Display red border and error message for invalid input
  • Disable submit button when validation fails
  • +17/-7   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @codiumai-pr-agent-free
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis 🔶

    929 - Partially compliant

    Compliant requirements:

    • Prevent Unicode values in input fields

    Non-compliant requirements:

    • Prevent empty slugs with generated postfixes
    • Prevent slugs starting with "-"
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Limited Validation

    The validation function only checks for alphanumeric characters but doesn't handle other valid ASCII characters like hyphens or underscores that might be needed in names.

    export function validateAsciiInput(value: string): boolean {
      const alphaNumericRegex = /^[A-Za-z0-9]*$/
      if (!alphaNumericRegex.test(value)) {
        return false
      }
      return true
    Incomplete Solution

    The current implementation prevents Unicode input but doesn't address the slug generation issue mentioned in the ticket where empty slugs get appended with postfixes.

    export function validateAsciiInput(value: string): boolean {
      const alphaNumericRegex = /^[A-Za-z0-9]*$/
      if (!alphaNumericRegex.test(value)) {
        return false
      }
      return true

    @codiumai-pr-agent-free
    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Jul 1, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Allow common name characters

    The current regex only allows alphanumeric characters without spaces, hyphens,
    or underscores, which are commonly used in entity names. Consider expanding the
    regex pattern to include these characters for better user experience.

    apps/platform/src/lib/utils.ts [102-108]

     export function validateAsciiInput(value: string): boolean {
    -  const alphaNumericRegex = /^[A-Za-z0-9]*$/
    +  const alphaNumericRegex = /^[A-Za-z0-9_\-\s]*$/
       if (!alphaNumericRegex.test(value)) {
         return false
       }
       return true
     }
    • Apply / Chat
    Suggestion importance[1-10]: 7

    __

    Why: This is a good suggestion that improves usability by allowing common characters like spaces, hyphens, and underscores in names, which is a reasonable expectation.

    Medium
    Fix misleading function name
    Suggestion Impact:The function name was changed from validateAsciiInput to validateAlphanumericInput as suggested. The commit also refactored the function body to be more concise, but this was not part of the original suggestion.

    code diff:

    -export function validateAsciiInput(value: string): boolean {
    +export function validateAlphanumericInput(value: string): boolean {

    The function name validateAsciiInput is misleading since it's actually
    validating for alphanumeric characters, not all ASCII characters. Rename the
    function to better reflect its purpose.

    apps/platform/src/lib/utils.ts [102-108]

    -export function validateAsciiInput(value: string): boolean {
    +export function validateAlphanumericInput(value: string): boolean {
       const alphaNumericRegex = /^[A-Za-z0-9]*$/
       if (!alphaNumericRegex.test(value)) {
         return false
       }
       return true
     }

    [Suggestion processed]

    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly identifies that the function name validateAsciiInput is misleading, as it only validates alphanumeric characters, and proposes a more accurate name, improving code clarity.

    Low
    Simplify function logic
    Suggestion Impact:The commit implemented the exact code simplification suggested, replacing the if-statement with a direct return of the regex test result. Additionally, the function was renamed from validateAsciiInput to validateAlphanumericInput.

    code diff:

       const alphaNumericRegex = /^[A-Za-z0-9]*$/
    -  if (!alphaNumericRegex.test(value)) {
    -    return false
    -  }
    -  return true
    +  return alphaNumericRegex.test(value)

    The function can be simplified by directly returning the result of the regex
    test, eliminating the unnecessary if statement and making the code more concise.

    apps/platform/src/lib/utils.ts [102-108]

     export function validateAsciiInput(value: string): boolean {
       const alphaNumericRegex = /^[A-Za-z0-9]*$/
    -  if (!alphaNumericRegex.test(value)) {
    -    return false
    -  }
    -  return true
    +  return alphaNumericRegex.test(value)
     }

    [Suggestion processed]

    Suggestion importance[1-10]: 4

    __

    Why: The suggestion correctly points out that the function can be simplified by directly returning the boolean result of alphaNumericRegex.test(value), which makes the code more concise.

    Low
    • Update

    @github-actions
    Copy link
    Contributor

    github-actions bot commented Jul 3, 2025

    @Allan2000-Git, please resolve all open reviews!

    @github-actions
    Copy link
    Contributor

    github-actions bot commented Jul 6, 2025

    @Allan2000-Git, please resolve all open reviews; otherwise this PR will be closed after Tue Jul 08 2025 18:32:15 GMT+0000 (Coordinated Universal Time)!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    platform: allowing unicode in values and passing

    2 participants