Skip to content

[$250] Report-Creating a text report field with name < > creates duplicate fields #74675

Closed

Description

@mitarachim

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.2.47-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #72375
Email or phone of affected tester (no customers): slottwo1alefish@gmail.com
Issue reported by: Applause Internal Team
Device used: Redminote 10s android 13
App Component: Workspace Settings

Action Performed:

Preconditions:
*Workspace created
*Report Fields feature enabled

1.Launch the app
2.Go to Workspace Settings → Reports → Report Fields
3.Tap Add Field
4.Enter Name: < >
5.Select Type: Text
6.Leave Initial Value empty
7.Tap Save
8.Observe the report field list

Expected Result:

Only one report field should be created with the name < >.

Actual Result:

Two report fields are created instead of one.
Both fields appear with the same name < >.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug6997904_1762597628779.Screenrecorder-2025-11-08-15-56-43-245.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021988198188857296747
  • Upwork Job ID: 1988198188857296747
  • Last Price Increase: 2025-11-11
Issue OwnerCurrent Issue Owner: @NikkiWines

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 10, 2025
  2. melvin-bot commented on Nov 10, 2025

    @melvin-bot

    Triggered auto assignment to @dylanexpensify (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.

  3. daledah commented on Nov 10, 2025

    @daledah
    Contributor

    Proposal

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

    Two report fields are created instead of one.
    Both fields appear with the same name < >.

    What is the root cause of that problem?

    When creating a new report field with the name < >, the Back End is returning another report field with the id field_id_

    Image

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

    We should filter that redundant report field and also in MoneyRequestViewReportFields component

            return Object.fromEntries(Object.entries(policy.fieldList).filter(([_, value]) => value.fieldID !== 'text_title' && value.fieldID !== 'field_id_'));
    

    const filteredPolicyFieldList = useMemo(() => {
    if (!policy?.fieldList) {
    return {};
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    return Object.fromEntries(Object.entries(policy.fieldList).filter(([_, value]) => value.fieldID !== 'text_title'));
    }, [policy]);

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. TaduJR commented on Nov 10, 2025

    @TaduJR
    Contributor

    Proposal

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

    When creating a text report field with the name < > (or any name containing angle brackets), two duplicate report fields are created instead of one. Both fields appear with the same name < > in the report fields list.

    What is the root cause of that problem?

    The root cause is a mismatch between frontend and backend fieldID generation logic when handling angle bracket characters (< and >).

    The API Call

    The frontend makes a call to the CreatePolicyReportField API endpoint:

    CREATE_WORKSPACE_REPORT_FIELD: 'CreatePolicyReportField',

    API.write(WRITE_COMMANDS.CREATE_WORKSPACE_REPORT_FIELD, parameters, onyxData);

    The Mismatch

    When a user creates a report field with name < >:

    1. Frontend generates: fieldID: "field_id_<_>" (keeps angle brackets)
    2. Backend (CreatePolicyReportField API) strips angle brackets and returns: fieldID: "field_id_" (without angle brackets)

    This creates two different entries in the policy's fieldList:

    • Optimistic data creates: expensify_field_id_<_>
    • Backend response creates: expensify_field_id_

    Both entries have the same name: "< >" but different fieldID values, causing two fields to appear in the UI.

    Evidence from API Request/Response

    Request to CreatePolicyReportField API:

    POST /api/CreatePolicyReportField
    {
      "policyID": "54EC812485A9EB3C",
      "reportFields": "[{\"name\":\"< >\",\"type\":\"text\",\"fieldID\":\"field_id_<_>\",\"orderWeight\":2,...}]"
    }
    

    Backend Response:

    {
      "policy": {
        "fieldList": [
          {
            "type": "text",
            "fieldID": "field_id_",
            "name": "< >",
            "orderWeight": 2
          }
        ]
      },
      "onyxData": [
        {
          "key": "policy_54EC812485A9EB3C",
          "onyxMethod": "merge",
          "value": {
            "fieldList": {
              "expensify_field_id_": {
                "fieldID": "field_id_",
                "name": "< >"
              }
            }
          }
        }
      ]
    }

    The backend's CreatePolicyReportField API silently strips < and > characters from the fieldID, but the frontend is unaware of this sanitization, leading to the duplicate entries.

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

    We should sanitize angle brackets in the frontend's generateFieldID function to match the backend's behavior. This prevents the optimistic/server data mismatch.

    Change Location

    /**
    * Generates a field ID based on the field name.
    */
    function generateFieldID(name: string) {
    return `field_id_${name.replace(CONST.REGEX.ANY_SPACE, '_').toUpperCase()}`;
    }

    Current Implementation

    /**
     * Generates a field ID based on the field name.
     */
    function generateFieldID(name: string) {
        return `field_id_${name.replace(CONST.REGEX.ANY_SPACE, '_').toUpperCase()}`;
    }

    Proposed Implementation

    /**
     * Generates a field ID based on the field name.
     */
    function generateFieldID(name: string) {
        // Remove angle brackets to match backend behavior which strips them
        const sanitizedName = name.replace(/[<>]/g, '');
        return `field_id_${sanitizedName.replace(CONST.REGEX.ANY_SPACE, '_').toUpperCase()}`;
    }

    Why This Solution Works

    With this change, when a user creates a field named < >:

    1. Frontend generates: fieldID: "field_id_" (angle brackets removed)
    2. Backend returns: fieldID: "field_id_" (angle brackets removed)
    3. Result: Both create the same key expensify_field_id_ - no duplicates!

    The optimistic data and server response now create identical keys, preventing duplicate entries in the fieldList.

    What alternative solutions did you explore?

    Alternative 1: Filter out duplicate fieldIDs in the UI (Rejected)

    This approach filters out the field_id_ entry from display:

    // In WorkspaceReportsPage.tsx
    return Object.fromEntries(
      Object.entries(policy.fieldList).filter(
        ([_, value]) => value.fieldID !== 'text_title' && value.fieldID !== 'field_id_'
      )
    );

    Why rejected:

    • Only hides the symptom, doesn't fix the root cause
    • Duplicate entry still exists in Onyx/database
    • Hardcodes a magic string 'field_id_' that may conflict with legitimate field names
    • Requires filtering in multiple UI locations
    • Doesn't prevent the data integrity issue

    Alternative 2: Prevent angle brackets in validation (Rejected)

    Add validation to reject names containing < or >:

    if (/<|>/.test(name)) {
        errors[INPUT_IDS.NAME] = 'Field names cannot contain < or > characters';
    }

    Why rejected:

    • Too restrictive - users should be able to use these characters in field names
    • Only prevents the specific case, doesn't fix the underlying mismatch
    • The field name can contain angle brackets; it's only the fieldID generation that needs to handle them

    Alternative 3: Fix backend to preserve angle brackets (Not feasible)

    Change the backend to keep angle brackets in fieldIDs.

    Why rejected:

    • May have security implications (HTML/XML injection concerns)
    • Backend behavior is likely intentional for sanitization
    • Frontend fix is simpler and safer
  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 11, 2025
  6. changed the title [-]Report-Creating a text report field with name < > creates duplicate fields[/-] [+][$250] Report-Creating a text report field with name < > creates duplicate fields[/+] on Nov 11, 2025
  7. melvin-bot commented on Nov 11, 2025

    @melvin-bot
  8. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 11, 2025
  9. melvin-bot commented on Nov 11, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @jjcoffee (External)

  10. jjcoffee commented on Nov 11, 2025

    @jjcoffee
    Contributor

    @TaduJR's proposal sounds good to me! If we're sanitizing on the BE it makes sense to also do it on the FE and I agree that simply filtering/hiding the extra field is just a workaround. We may want to replace with some other char rather than just an empty string though, as otherwise you could end up with conflicting field_ids (multiple field_id_)?

    🎀👀🎀 C+ reviewed

  11. melvin-bot commented on Nov 11, 2025

    @melvin-bot

    Triggered auto assignment to @NikkiWines, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  12. NikkiWines commented on Nov 11, 2025

    @NikkiWines
    Contributor

    this kind of seems like a backend bug, since the the fieldID is incorrect for the given name. If we simply sanitize it on the front end like we do currently on the backend, we might run into issues where entries with other characters that get stripped have the same fieldID of field_id_?

    I'll take a look at what we're doing in the backend just to be sure. If that's not the case, then I agree that @TaduJR's proposal looks good.

  13. NikkiWines commented on Nov 12, 2025

    @NikkiWines
    Contributor

    OK yeah we're doing some sanitization on the backend that I think we might be able to adjust, making this internal for now. Sorry about that and thank you for the proposals!

  14. added
    InternalRequires API changes or must be handled by Expensify staff
    and removed
    ExternalAdded to denote the issue can be worked on by a contributor
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 12, 2025
  15. self-assigned this
    on Nov 12, 2025
  16. c3024 commented on Nov 17, 2025

    @c3024
    Contributor

    PR in review.

  17. c3024 commented on Nov 19, 2025

    @c3024
    Contributor

    https://github.com/Expensify/Web-Expensify/pull/49448 deployed to production. This should be fixed.

    @mitarachim , can you please retest?

  18. mitarachim commented on Nov 19, 2025

    @mitarachim
    Author

    Hello @c3024 QA team unable to reproduce issue using latest build v9.2.60-1

    Screenrecorder-2025-11-19-08-27-31-228.mp4
  19. c3024 commented on Nov 19, 2025

    @c3024
    Contributor

    Thanks!

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.DailyKSv2InternalRequires API changes or must be handled by Expensify staffReviewingHas a PR in review

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions