Skip to content

🐛: Attribute size field in console allows the character "e" to be typed when it should only allows whole numbers #9217

Closed

Description

@viknith

👟 Reproduction steps

  1. Go to Attributes, and click "Create attribute". Pick any value option except boolean.
  2. In the size field, it seems to not allow any alphabet character and should only be expecting whole numbers
  3. However, in the size field, I'm able to type the letter "e". When I submit, I get an inaccurate error message for the problem.

👍 Expected behavior

I shouldn't be able to type the letter e. And tbh, I shouldn't be able to type a period either for decimals since it expects whole numbers, but the error message is nicely stated there.

👎 Actual Behavior

Image

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

MacOS

🧱 Your Environment

Console

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Activity

  1. added
    bug
    on Jan 13, 2025
  2. changed the title [-]🐛: Attribute size field in console allows the character "e" and "." to be typed when it only expects whole numbers[/-] [+]🐛: Attribute size field in console allows the character "e" to be typed when it only expects whole numbers[/+] on Jan 13, 2025
  3. changed the title [-]🐛: Attribute size field in console allows the character "e" to be typed when it only expects whole numbers[/-] [+]🐛: Attribute size field in console allows the character "e" to be typed when it should only allows whole numbers[/+] on Jan 13, 2025
  4. added
    product / databases
    product / cloud
    on Jan 15, 2025
  5. arilui commented on Jan 27, 2025

    @arilui

    I'm working on this

  6. IgorJanGit commented on Jan 30, 2025

    @IgorJanGit

    I am working on this

  7. added
    product / console
    and removed
    product / cloud
    on Jan 30, 2025
  8. Bayyana-kiran commented on Feb 5, 2025

    @Bayyana-kiran

    Hey @viknith, I tried using different characters and found that . and -- are also allowed in the numbers field. I’d like to contribute to this issue. And I got know that the error is in-Built php value where

    ->param('size', null, new Range(1, APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH, Range::TYPE_INTEGER), 'Attribute size for text attributes, in number of characters.')

    Where the error is TYPE_INTEGER it allows the "e" values because of exponential notation and also "." is also allowed due to decimal values and -- is allowed because of decrement values.

    Image Image

    Could you please assign it to me?

  9. viknith commented on Feb 6, 2025

    @viknith
    Author

    I don't think there's any assigning process, just go ahead and work on it if you'd like :), I'm just a dude passing by that noticed this while playing around with AppWrite.

  10. Bayyana-kiran commented on Feb 7, 2025

    @Bayyana-kiran

    @viknith I'm working on it and I will try to merge it 😄

  11. Bayyana-kiran commented on Feb 20, 2025

    @Bayyana-kiran

    @viknith Hey I got an doubt The input field need to allow only whole numbers only because I'm trying to code up a regex for that.

  12. D0CT4 commented on Oct 21, 2025

    @D0CT4

    @Bayyana-kiran Good catch on identifying the root cause! Here's the best way to fix this:

    The Problem

    You're correct - Range::TYPE_INTEGER uses PHP's is_numeric() which accepts:

    • Exponential notation ("1e5")
    • Decimals ("3.14")
    • Negative signs ("--5")

    The Solution

    Don't use regex for this. Instead, create a proper integer validator. Here's the approach:

    Option 1: Update the Range Validator (Cleanest)

    In /src/Utopia/Validator/Range.php, modify the validation:

    protected function isValid($value): bool
    {
        if ($this->type === self::TYPE_INTEGER) {
            // Use ctype_digit for strict integer validation (no e, ., -)
            if (!ctype_digit((string)$value)) {
                return false;
            }
            $value = (int)$value;
        }
        
        // ... rest of range checking
    }

    Option 2: Add Client-Side Validation (Quick Win)

    In the Console form component, add HTML5 validation:

    <input 
      type="number" 
      step="1"
      min="1"
      max="{APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH}"
      pattern="[0-9]+"
      oninput="this.value = this.value.replace(/[^0-9]/g, '')"
    />

    The oninput handler immediately strips non-digits, preventing "e", ".", and "--" from being typed.

    Option 3: Both (Best Approach)

    Do both - fix the server-side validator AND add client-side prevention for better UX.

    Why Not Regex?

    Regex works, but it's overkill here. ctype_digit() is:

    • Faster
    • More readable
    • Built for this exact use case
    • Already used elsewhere in Appwrite codebase

    Testing

    Make sure to test:

    // Should PASS
    $validator->isValid("100");
    $validator->isValid("1");
    
    // Should FAIL
    $validator->isValid("1e5");   // exponential
    $validator->isValid("3.14");  // decimal
    $validator->isValid("--5");   // double negative
    $validator->isValid("-5");    // negative (if min is 1)

    Let me know if you need help with the PR! I've worked on similar input validation issues before and can review.

  13. Bayyana-kiran commented on Oct 22, 2025

    @Bayyana-kiran

    Ok @D0CT4 I will try to work on it.

  14. saaahilhussain commented on Oct 20, 2026

    @saaahilhussain

    Hi @Meldiron! I've reproduced #9217 in the current Appwrite Console and traced the underlying input-handling issue.

    Under TablesDB → Columns → Create Column → Varchar, I observed:

    • Typing e leaves it visible even after losing focus.
    • Pasting 1e3 silently converts the Size value to 1.
    • Pasting 2.5 silently converts it to 2.

    The cause of the silent conversion is in apps/console/src/components/pages/projects/$projectId/databases/tablesdb/Column.tsx. Both Varchar and deprecated String use parseInt() without validating the complete input, allowing invalid numeric representations to be truncated.

    Proposed fix: Preserve the raw Size input, validate it as a whole number, and convert it only after validation. I'll also add regression coverage for invalid input, valid boundaries, and both affected column types.

    One implementation detail I'd like your input on: should invalid characters be rejected immediately, or preserved with an inline validation error?

    I'd like to take ownership of this fix. Could you confirm the preferred behavior and assign #9217 to me so I can proceed?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugproduct / consoleproduct / databases

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions