Clawith icon indicating copy to clipboard operation
Clawith copied to clipboard

[Bug] Company creation fails with 422 error when company name contains Chinese characters

Open Clawiee opened this issue 8 months ago • 3 comments

Tags: bug, ui, configuration Quality Rating: ⭐ 8/10


Reporter: xiaoan

Description

When creating a company with a name containing Chinese characters, the slug generation logic produces an empty string, resulting in a 422 error response from the API.

Steps to Reproduce

  1. Navigate to the company creation page (Layout.tsx)
  2. Enter a company name that contains Chinese characters (e.g., "我的公司")
  3. Submit the form
  4. Observe the 422 error

Expected Behavior

The company should be created successfully, with a valid slug generated from the company name.

Actual Behavior

The slug generation removes all Chinese characters, resulting in an empty string. This causes the API to return a 422 error and the company creation fails.

Code Location

File: src/pages/Layout.tsx Line: 290

const slug = newCompanyName.toLowerCase().replace(/[\s]+/g, '-').replace(/[^a-z0-9_-]/g, '').slice(0, 50);

Root Cause

The regex pattern /[^a-z0-9_-]/g removes all non-ASCII characters, including Chinese characters, leaving an empty string when the company name contains only Chinese.

Suggested Solution

  1. Option 1: Support Chinese characters in slug generation by updating the regex pattern
  2. Option 2: Convert Chinese characters to pinyin before slug generation (e.g., using a library like pinyin-pro)
  3. Option 3: Implement a fallback mechanism that generates a timestamp-based slug when the primary method fails

Additional Context

This issue affects any user creating a company with a non-ASCII name. A robust slug generation solution would improve the user experience for international users.

Clawiee avatar Mar 13 '26 20:03 Clawiee

Additional Context (Issue Origin):

This bug was discovered during the company creation workflow. The user is unable to create a new company when using a Chinese company name. This is a blocker issue that prevents users from setting up their workspace with Chinese company names.

Impact: Affects all users attempting to create companies with non-ASCII names (Chinese, Japanese, Korean, etc.), making it a critical UX issue for international users.

Clawiee avatar Mar 13 '26 20:03 Clawiee

Hi @xiaoan 👋

Thanks for reporting this issue! Great catch on the Chinese character slug generation problem.

Analysis

I found that this issue is actually being addressed in PR #62 ("fix: allow creating new company during registration"), which was just submitted. Let me explain:

Current Code Issue (before PR #62):

  • The slug generation regex /[^a-z0-9_-]/g strips all non-ASCII characters, including Chinese
  • If the company name is purely Chinese (e.g., "我的公司"), the slug becomes empty → 422 error

PR #62 Solution: The new generate_slug() function in backend/app/api/tenants_public.py (lines 19-25) adds a random UUID suffix:

def generate_slug(name: str) -> str:
    slug = re.sub(r'[^a-z0-9\s-]', '', name.lower())
    slug = re.sub(r'[\s-]+', '-', slug)
    return f"{slug}-{uuid.uuid4().hex[:6]}"  # ← UUID suffix ensures uniqueness even with empty slug

Why this works:

  • Even if the Chinese characters are stripped, the UUID suffix (-abc123) makes the slug valid
  • Example: "我的公司" → "" → "-a1b2c3" (valid slug)

Recommendation for better internationalization: While PR #62 fixes the immediate problem, you might also consider:

  1. Option A (future enhancement): Use python-pinyin library to convert Chinese to pinyin before slug generation
  2. Option B (current workaround): Users can mix English + Chinese in company names (e.g., "我的公司 MyCompany" → "mycompany-a1b2c3")

🌐 Language note: To help more community members participate in the discussion, could you please submit issues in English? You're welcome to include a translation in your original language as well. Thank you! 🙏

This analysis was generated by reviewing the Clawith source code. I'm a project assistant bot — please let the maintainers confirm before taking action.

Clawiee avatar Mar 13 '26 20:03 Clawiee

Hi @xiaoan 👋

Thanks for reporting this issue! I've analyzed the source code and confirmed the problem.

Analysis

Root Cause: The slug generation logic in frontend/src/pages/Layout.tsx (line 362) uses this regex:

const slug = newCompanyName.toLowerCase().replace(/[\s]+/g, '-').replace(/[^a-z0-9_-]/g, '').slice(0, 50);

The pattern /[^a-z0-9_-]/g removes all non-ASCII characters, including Chinese characters. When a company name contains only Chinese characters (e.g., "我的公司"), the slug becomes an empty string after this replacement, which causes the API to reject it with a 422 error.

Affected Code Path:

  • Frontend: frontend/src/pages/Layout.tsx → createCompany() function
  • Backend API: The tenant creation endpoint validates that slug is not empty

Suggested Solutions

  1. Option 1 (Recommended): Add a fallback mechanism that generates a UUID-based or timestamp-based slug when the primary method fails:

    let slug = newCompanyName.toLowerCase().replace(/[\s]+/g, '-').replace(/[^a-z0-9_-]/g, '').slice(0, 50);
    if (!slug.trim()) {
      slug = `company-${Date.now()}`; // or use a UUID
    }
    
  2. Option 2: Convert Chinese characters to pinyin before slug generation using a library like pinyin-pro:

    import pinyin from 'pinyin-pro';
    const pinyinName = pinyin(newCompanyName, { type: 'normal' });
    const slug = pinyinName.toLowerCase().replace(/[\s]+/g, '-').slice(0, 50);
    
  3. Option 3: Allow Unicode characters in slug validation (less recommended for URL-friendly slugs):

    const slug = newCompanyName.toLowerCase().replace(/[\s]+/g, '-').slice(0, 50);
    

Impact

This issue affects all users creating a company with non-ASCII names (Chinese, Japanese, Korean, Arabic, etc.), significantly limiting international usability.

Priority

🔴 HIGH — This is a critical blocker for non-English users during company creation.


This analysis was generated by reviewing the Clawith source code. I'm a project assistant bot — please let the maintainers confirm before taking action.

Clawiee avatar Mar 13 '26 21:03 Clawiee