Skip to content

Rules - Merchant Rule with special characters saved without error but disappeared later #81140

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: V9.3.11-17
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #80853
Email or phone of affected tester (no customers): dreamnitethedragon+yydyd373@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redminote 10S Android 13
App Component: Workspace Settings

Action Performed:

  1. Launch app
  2. Create a workspace
  3. Tap more features - Enable Rules
  4. Tap Rules
  5. Tap Add merchant rule
  6. Enter a merchant
  7. Enter merchant as <Shahrukh&bro> under apply these updates and save

Expected Result:

Merchant Rule saved with special characters must show invalid character error and must not allow to save the rule.

Actual Result:

Merchant Rule with special characters is saved without error but disappeared later.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @luacmartins

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 2, 2026
  2. melvin-bot commented on Feb 2, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #80853

  3. melvin-bot commented on Feb 2, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. melvin-bot commented on Feb 2, 2026

    @melvin-bot

    Triggered auto assignment to @JmillsExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. github-actions commented on Feb 2, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. OSBotify commented on Feb 2, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #80853 - "Remove dev lock from merchant rules" by @luacmartins (High confidence)
    Related Issues: #80855 (feature enablement issue)

    Recommendation: ROLL FORWARD

    The issue should be fixed by adding proper client-side validation for special characters in merchant rule names. Reverting PR #80853 would simply hide the merchant rules feature again, which is not the desired outcome since this feature was intentionally enabled for release.

    Labels: Keeping DeployBlockerCash (App deploy is blocked). Removing DeployBlocker if present (not a backend issue).

    📋 Detailed Analysis

    Evidence

    PR #80853 enabled merchant rules for all users by changing the environment check from isDevelopment to isProduction. This exposed a pre-existing validation gap: the frontend allows merchant names with special characters (like &) to be entered and saved without validation, but the backend subsequently rejects them, causing the rule to disappear.

    The frontend validation in src/components/Rule/TextBase.tsx only checks:

    • Required field fulfillment
    • Character length (max bytes)

    There is no validation for special/invalid characters in merchant names.

    Verification

    • Examined src/pages/workspace/rules/MerchantRules/AddMerchantPage.tsx - uses RuleTextBase component
    • Examined src/components/Rule/TextBase.tsx - contains only basic validation (required, length)
    • Examined src/libs/actions/Policy/Rules.ts - no client-side validation for special characters before API call
    • PR Remove dev lock from merchant rules #80853 modified only src/pages/workspace/rules/MerchantRulesSection.tsx to change the feature flag

    Root Cause

    The merchant rules feature was released without comprehensive input validation. When users enter merchant names with special characters like &, the frontend optimistically displays the rule as saved, but the backend silently rejects it (likely due to character encoding or SQL injection prevention), causing the rule to disappear from the UI.

    The fix requires adding client-side validation to:

    1. Validate allowed characters in merchant names before saving
    2. Display clear error messages when invalid characters are entered
    3. Prevent the form from being submitted with invalid data
  7. luacmartins commented on Feb 2, 2026

    @luacmartins
    Contributor

    NAB feature is not available in prod.

  8. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Feb 2, 2026
  9. marufsharifi commented on Feb 2, 2026

    @marufsharifi

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Rules - Merchant Rule with special characters saved without error but disappeared later

    What is the root cause of that problem?

    The merchant‑rule input flows do not validate special characters at all. They only check required + length. So invalid data gets past the UI and the API rollback removes the optimistic rule, which looks like it “disappeared.”

    Root-cause code (current behavior):

    if (!isRequiredFulfilled(fieldValue)) {
    errors[fieldID] = translate('common.error.fieldRequired');
    } else {
    const {isValid, byteLength} = isValidInputLength(trimmedValue, CONST.MERCHANT_NAME_MAX_BYTES);
    if (!isValid) {
    errors[fieldID] = translate('common.error.characterLimitExceedCounter', byteLength, CONST.MERCHANT_NAME_MAX_BYTES);
    }
    }

    if (isRequired && !isRequiredFulfilled(fieldValue)) {
    (errors as Record<string, string>)[fieldID] = translate('common.error.fieldRequired');
    } else {
    const {isValid, byteLength} = isValidInputLength(trimmedValue, characterLimit);
    if (!isValid) {
    (errors as Record<string, string>)[fieldID] = translate('common.error.characterLimitExceedCounter', byteLength, characterLimit);
    }
    }

    What changes do you think we should make in order to solve the problem?

    Add explicit client-side validation for invalid characters (minimal set: < and >) and reuse it across merchant‑rule inputs. This prevents invalid rules from being saved and avoids the “saved then disappears” behavior.

    1. Add a shared validator for merchant‑rule characters

    diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts
    @@
     function isValidPersonName(value: string) {
         return /^[^\d^!#$%*=<>;{}"]+$/.test(value);
     }
     
    +/**
    + * Checks that merchant rule values don't contain angle brackets.
    + */
    +function hasInvalidMerchantRuleCharacters(value: string): boolean {
    +    return value.includes('<') || value.includes('>');
    +}
    @@
         isValidPersonName,
    +    hasInvalidMerchantRuleCharacters,

    2. Allow rule text inputs to accept a custom validator

    diff --git a/src/components/Rule/TextBase.tsx b/src/components/Rule/TextBase.tsx
    @@
     type TextBaseProps<TFormID extends OnyxFormKey> = {
    @@
         onSubmit: (values: FormOnyxValues<TFormID>) => void;
    +    validateInput?: (value: string) => string | undefined;
     };
    @@
    -        if (isRequired && !isRequiredFulfilled(fieldValue)) {
    +        if (isRequired && !isRequiredFulfilled(fieldValue)) {
                 (errors as Record<string, string>)[fieldID] = translate('common.error.fieldRequired');
             } else {
    +            const validationError = validateInput?.(trimmedValue);
    +            if (validationError) {
    +                (errors as Record<string, string>)[fieldID] = validationError;
    +                return errors;
    +            }
                 const {isValid, byteLength} = isValidInputLength(trimmedValue, characterLimit);
    diff --git a/src/components/Rule/RuleTextBase.tsx b/src/components/Rule/RuleTextBase.tsx
    @@
     type RuleTextBaseProps<TFormID extends OnyxFormKey> = {
    @@
         hash?: string;
    +    validateInput?: (value: string) => string | undefined;
     };
    @@
                     <TextBase
    @@
                         characterLimit={characterLimit}
    +                    validateInput={validateInput}
                     />

    3. Enforce invalid‑character validation for “rename merchant”

    diff --git a/src/pages/workspace/rules/MerchantRules/AddMerchantPage.tsx b/src/pages/workspace/rules/MerchantRules/AddMerchantPage.tsx
    @@
     import RuleTextBase from '@components/Rule/RuleTextBase';
    +import useLocalize from '@hooks/useLocalize';
    @@
    +import {hasInvalidMerchantRuleCharacters} from '@libs/ValidationUtils';
    @@
    +    const {translate} = useLocalize();
    @@
    +    const validateMerchantName = (value: string) => (hasInvalidMerchantRuleCharacters(value) ? translate('common.error.invalidCharacter') : undefined);
    @@
                 onBack={goBack}
    +            validateInput={validateMerchantName}
             />

    4. Enforce invalid‑character validation for “merchant to match”

    diff --git a/src/pages/workspace/rules/MerchantRules/AddMerchantToMatchPage.tsx b/src/pages/workspace/rules/MerchantRules/AddMerchantToMatchPage.tsx
    @@
    -import {isRequiredFulfilled, isValidInputLength} from '@libs/ValidationUtils';
    +import {hasInvalidMerchantRuleCharacters, isRequiredFulfilled, isValidInputLength} from '@libs/ValidationUtils';
    @@
             if (!isRequiredFulfilled(fieldValue)) {
                 errors[fieldID] = translate('common.error.fieldRequired');
             } else {
    +            if (hasInvalidMerchantRuleCharacters(trimmedValue)) {
    +                errors[fieldID] = translate('common.error.invalidCharacter');
    +                return errors;
    +            }
                 const {isValid, byteLength} = isValidInputLength(trimmedValue, CONST.MERCHANT_NAME_MAX_BYTES);

    What alternative solutions did you explore? (Optional)

    Alternative 1: Enable Strict HTML Tag Validation Flag

    Add shouldUseStrictHtmlTagValidation flag to FormProvider in TextBase.tsx.

    Benefit: Uses existing infrastructure, minimal code change.

    Cons:

    • Too broad scope - affects all RuleTextBase uses, not just merchant rules
    • Incomplete coverage - only catches <...> pairs, not lone < or > (e.g., "ACME <" would pass)
    • Less explicit intent

    Chosen Solution: Custom hasInvalidMerchantRuleCharacters() function is more targeted, catches ALL angle bracket cases, and has clear intent.

  10. luacmartins commented on Feb 2, 2026

    @luacmartins
    Contributor

    I'm working on this

  11. added
    ReviewingHas a PR in review
    and removed on Feb 2, 2026
  12. luacmartins commented on Feb 2, 2026

    @luacmartins
    Contributor

    PR in review

  13. luacmartins commented on Feb 3, 2026

    @luacmartins
    Contributor

    PR merged, we can close this.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions