Skip to content

[Due for payment 2026-02-23] Expense - Limit value merges with keyword when saved with space #81166

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?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #80262
Email or phone of affected tester (no customers): dreamnitethedragon@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redminote 10S Android 13
App Component: User Settings

Action Performed:

  1. Launch app
  2. Go to reports - filter - Expense
  3. Enter keyword "hi" & save
  4. Enter limi as "10 90" & save
  5. Tap save search
  6. Tap filter
  7. Note keyword field shown as "hi 90"

Expected Result:

Reopening the filter after saving the search should show the keyword field as "hi" and the limit field as "10 90" as user entered.

Actual Result:

After entering keyword "hi" and limit "10 90" in filter and saving the search, reopening the filter shows the keyword field as "hi 90" instead of "hi".

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: @TaduJR

Activity

  1. daledah commented on Feb 2, 2026

    @daledah
    Contributor

    Proposal

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

    After entering keyword "hi" and limit "10 90" in filter and saving the search, reopening the filter shows the keyword field as "hi 90" instead of "hi".

    What is the root cause of that problem?

    After entering keyword "hi" and limit "10 90" in filter and saving the search, reopening the filter shows the keyword field as "hi 90" instead of "hi".

    The root cause is in how the search query is parsed. When user enters limit:10 90 in the limit field:

    1. The search parser only accepts numeric values for limit (defined in searchParser.peggy)

    "type", "keyword", "groupCurrency", "groupBy", "columns", "limit", "view"

    1. The parser correctly parses limit:10 but treats 90 as a freetext filter
    2. Freetext filters are automatically converted to keyword filters (see line 161-176 in searchParser.peggy)
    3. When reopening the filter, buildFilterFormValuesFromQuery combines all keyword values using space delimiter, resulting in hi 90

    The issue is in the buildSearchQueryString function where keywords are built using space as delimiter, and the invalid limit value 90 gets added as a keyword.

    function buildSearchQueryString(queryJSON?: SearchQueryJSON) {
    const queryParts: string[] = [];
    const defaultQueryJSON = buildSearchQueryJSON('');
    // Check if view was explicitly set by the user (exists in rawFilterList or differs from default)
    const wasViewExplicitlySet =
    (queryJSON?.rawFilterList?.some((filter) => filter.key === CONST.SEARCH.SYNTAX_ROOT_KEYS.VIEW) ?? false) || (queryJSON?.view && queryJSON.view !== defaultQueryJSON?.view);
    for (const [, key] of Object.entries(CONST.SEARCH.SYNTAX_ROOT_KEYS)) {
    // Skip view if it wasn't explicitly set by the user
    if (key === CONST.SEARCH.SYNTAX_ROOT_KEYS.VIEW && !wasViewExplicitlySet) {
    continue;
    }
    const existingFieldValue = queryJSON?.[key];
    const queryFieldValue = existingFieldValue ?? defaultQueryJSON?.[key];
    if (queryFieldValue) {
    if (Array.isArray(queryFieldValue)) {
    queryParts.push(`${key}:${queryFieldValue.join(',')}`);
    } else {
    queryParts.push(`${key}:${queryFieldValue}`);
    }
    }
    }
    if (queryJSON?.policyID) {
    queryParts.push(`${CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID}:${Array.isArray(queryJSON.policyID) ? queryJSON.policyID.join(',') : queryJSON.policyID}`);
    }
    if (!queryJSON) {
    return queryParts.join(' ');
    }
    const filters = queryJSON.flatFilters;
    for (const filter of filters) {
    const filterValueString = buildFilterValuesString(filter.key, filter.filters);
    queryParts.push(filterValueString.trim());
    }
    return queryParts.join(' ');
    }

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

    We should validate the limit input field to only accept valid numeric values before saving. The validation should be added in the SearchFiltersLimitPage to prevent invalid limit values from being saved:

    --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersLimitPage.tsx
    +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersLimitPage.tsx
    @@ -1,5 +1,6 @@
     import React, {useCallback} from 'react';
     import {View} from 'react-native';
    +import * as ErrorUtils from '@libs/ErrorUtils';
     import FormProvider from '@components/Form/FormProvider';
     import InputWrapper from '@components/Form/InputWrapper';
     import type {FormOnyxValues} from '@components/Form/types';
    @@ -24,6 +25,17 @@ function SearchFiltersLimitPage() {
         const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true});
         const limitValue = searchAdvancedFiltersForm?.limit;
    
    +    const validate = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM>) => {
    +        const errors: Record<string, string> = {};
    +        const limit = values.limit?.toString().trim();
    +        
    +        if (limit && (!/^\d+$/.test(limit) || Number(limit) <= 0)) {
    +            errors.limit = translate('common.error.enterValidNumber');
    +        }
    +        
    +        return errors;
    +    }, [translate]);
    +
         const updateLimitFilter = useCallback(
             (values: FormOnyxValues<typeof ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM>) => {
                 updateAdvancedFilters({limit: values.limit});
    @@ -44,6 +56,7 @@ function SearchFiltersLimitPage() {
                 <FormProvider
                     formID={ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM}
                     onSubmit={updateLimitFilter}
    +                validate={validate}
                     submitButtonText={translate('common.save')}
                     style={[styles.mh5, styles.flex1]}
                 >

    What alternative solutions did you explore? (Optional)

    An alternative approach would be to sanitize the limit value when building the query string in buildQueryStringFromFilterFormValues, extracting only the first valid number. However, this would mask the user's input error rather than providing clear feedback about what went wrong.

  2. TaduJR commented on Feb 2, 2026

    @TaduJR
    Contributor

    Assignment here @trjExpensify

  3. samranahm commented on Feb 2, 2026

    @samranahm
    Contributor

    Proposal

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

    When a user saves an Expense search with keyword "hi" and limit "10 90", reopening the filter shows keyword as "hi 90" and the limit value is wrong. Keyword and limit values that contain spaces get merged so the filter form no longer matches what was saved.

    What is the root cause of that problem?

    The query string is built by joining filter parts with spaces. The limit value is written without quoting:

    The search parser treats space as a separator. So ... keyword:hi limit:10 90 is parsed as: keyword "hi", limit "10", and "90" as a separate free-text token. Free text is merged into the keyword filter (see searchParser.peggy L186–L195). So after parse, keyword becomes "hi 90" and limit "10". Root cause: limit is not quoted when it contains spaces, so the part after the space is mis-parsed as keyword.

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

    Quote the limit value when it contains spaces (or nbsp), using the existing sanitizeSearchValue helper, so the parser receives e.g. limit:"10 90" and keeps it as one value.

    src/libs/SearchQueryUtils.ts When pushing the limit into filtersString, pass the value through sanitizeSearchValue so values with spaces are wrapped in double quotes (same behavior as other filters that use sanitizeSearchValue L124–L129).

         const limitValue = limit ?? options?.limit;
         if (limitValue !== undefined) {
    -        filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.LIMIT}:${limitValue}`);
    +        const limitStr = typeof limitValue === 'number' ? String(limitValue) : limitValue;
    +        filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.LIMIT}:${sanitizeSearchValue(limitStr)}`);
         }

    This way limit:10 90 becomes limit:"10 90", the parser keeps "10 90" as the limit, and the keyword stays "hi".

    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. trjExpensify commented on Feb 2, 2026

    @trjExpensify
    Contributor

    Assigning the team from: #80262

  5. cosmicvulpes commented on Feb 2, 2026

    @cosmicvulpes
    Contributor

    Proposal

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

    When a user enters a keyword (e.g., "hi") and a limit with a space (e.g., "10 90") in the expense filter, saves the search, and then reopens the filter, the keyword field incorrectly shows "hi 90" instead of "hi". The "90" from the limit input has merged into the keyword field.

    What is the root cause of that problem?

    The root cause is in the buildQueryStringFromFilterFormValues function in src/libs/SearchQueryUtils.ts. When converting form values to a query string, the limit value is added without any validation or sanitization:

    const limitValue = limit ?? options?.limit;
    if (limitValue !== undefined) {
    filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.LIMIT}:${limitValue}`);
    }

    const limitValue = limit ?? options?.limit;
    if (limitValue !== undefined) {
        filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.LIMIT}:${limitValue}`);
    }

    When a user enters 10 90 as the limit value, this produces limit:10 90 in the query string. When the search parser (searchParser.peggy) parses this query:

    1. limit:10 is parsed as a default filter with value 10
    2. 90 becomes a free text filter, which is treated as a keyword

    freeTextFilter
    = _ value:(quotedString / [^ \t\r\n\xA0]+) _ {
    //handle no-breaking space
    let word;
    if (Array.isArray(value)) {
    word = value.join("");
    } else {
    word = value;
    }
    return buildFilter("eq", "keyword", word);
    }

    The parser's identifier rule only accepts comma-separated values, not space-separated ones:

    identifier
    = (","+)? parts:(values / quotedString / alphanumeric)|1.., ","+| empty:(","+)? {
    const value = parts.flat().filter(Boolean).map((word) => {
    if (word.startsWith('"') && word.endsWith('"') && word.length >= 2) {
    return word.slice(1, -1);
    }
    return word;
    });
    if (value.length > 1) {
    return value.filter((word) => word.length > 0);
    }
    return value[0];
    }

    So when the saved search is loaded back and buildFilterFormValuesFromQuery reconstructs the form values, the 90 is combined with the existing keyword hi, resulting in "hi 90".

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

    Sanitize the limit value in buildQueryStringFromFilterFormValues before adding it to the query string. Since limit must be a positive integer (as validated in buildSearchQueryJSON at lines 445-448), we should extract only the first valid positive integer from the input:

    In src/libs/SearchQueryUtils.ts, modify the limit handling around line 749:

    const limitValue = limit ?? options?.limit;
    if (limitValue !== undefined) {
        // Extract only the first valid positive integer from the limit value
        const sanitizedLimit = typeof limitValue === 'string' ? limitValue.trim().split(/\s+/)[0] : limitValue;
        const numericLimit = Number(sanitizedLimit);
        if (Number.isInteger(numericLimit) && numericLimit > 0) {
            filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.LIMIT}:${numericLimit}`);
        }
    }

    This ensures:

    1. Only the first token (before any space) is used
    2. The value is validated to be a positive integer before being added
    3. Invalid limit values are silently ignored rather than corrupting other filter fields

    What alternative solutions did you explore? (Optional)

    NA

  6. 14 remaining items

  7. changed the title [-]Expense - Limit value merges with keyword when saved with space[/-] [+][Due for payment 2026-02-23] Expense - Limit value merges with keyword when saved with space[/+] on Feb 16, 2026
  8. melvin-bot commented on Feb 16, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  9. melvin-bot commented on Feb 16, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.19-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-02-23. 🎊

    For reference, here are some details about the assignees on this issue:

    • @ShridharGoel requires payment through NewDot Manual Requests
    • @TaduJR requires payment (Needs manual offer from BZ)
  10. melvin-bot commented on Feb 23, 2026

    @melvin-bot

    Issue is ready for payment but no BZ is assigned. @sonialiap you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

  11. sonialiap commented on Feb 23, 2026

    @sonialiap
    Contributor

    Payment summary:
    Part of a project, no payment needed on this issue

    @ShridharGoel $250 please request through NewDot
    @TaduJR $250 offer sent in upwork

  12. ShridharGoel commented on Feb 23, 2026

    @ShridharGoel
    Contributor

    @trjExpensify Is this considered a part of the insights project or is it separate?

  13. trjExpensify commented on Feb 23, 2026

    @trjExpensify
    Contributor

    Yeah, this is part of Insights as clean up for the Limit filter. We don't need to process payments here. 👍

  14. sonialiap commented on Feb 24, 2026

    @sonialiap
    Contributor

    Updating Payment summary to no payment needed

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions