Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.57k stars 2.91k forks source link

Search - Quotation marks in search query increase each time when switching status #52923

Open lanitochka17 opened 12 hours ago

lanitochka17 commented 12 hours ago

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: 9.0.65-3 Reproducible in staging?: Y Reproducible in production?: Y If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): applausetester+kh0811007@applause.expensifail.com Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to Search
  3. Click Filters
  4. Click Has keywords
  5. Enter this full link - https://google.com/
  6. Save it
  7. Click View results
  8. Click on any status many times

Expected Result:

The search query will not change when switching status

Actual Result:

The quotation marks in search query increase each time when switching status

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/de7422e5-77f8-4823-ac3a-189c08bfce5a

View all open jobs on GitHub

melvin-bot[bot] commented 12 hours ago

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

nyomanjyotisa commented 11 hours ago

Proposal

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

Search - Empty row in "In" field when searching for messages in inaccessible group chat

What is the root cause of that problem?

We always wrap the value with "" if the value contains special characters although it is already wrapped with "" https://github.com/Expensify/App/blob/76e0d1326f0d5b82115add4483798c4824b6e877/src/libs/SearchQueryUtils.ts#L39-L45

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

Don't wrap the value with "" again if the value already wrapped with ""

function sanitizeSearchValue(str: string) {
    const regexpDoubleQuotes = /^".*"$/;
    const regexp = /[^A-Za-z0-9_@./#&+\-\\';,"]/g;
    if (regexp.test(str) && !regexpDoubleQuotes.test(str)) {
        return `"${str}"`;
    }
    return str;
}

What alternative solutions did you explore? (Optional)

Or change to

function sanitizeSearchValue(str: string) {
    const regexp = /^(?!".*"$).*[^A-Za-z0-9_@./#&+\-\\';,"]/;
    if (regexp.test(str)) {
        return `"${str}"`;
    }
    return str;
}
Tony-MK commented 3 hours ago

Proposal

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

Search - Quotation marks in search query increase each time when switching status

What is the root cause of that problem?

In the saveSearch function queryJSON is converted to a JSON string before it's sent to WRITE_COMMANDS.SAVE_SEARCH.

The problem is that JSON.stringify() will add a pair of double quotation marks to the beginning and end of the keywords in the filter array to make sure the JSON string is up to JSON's expectations.

https://github.com/Expensify/App/blob/85d8b8849cf3cafe9b9a5a9bf025df4f5148c77c/src/libs/actions/Search.ts#L54-L56

After the search is saved, the keyword filters have the quotation marks and the searchParser.parse function will treat the extra quotation marks as part of the keyword.

https://github.com/Expensify/App/blob/686b8b45ca606453e4b8a5f11e2a16e75dd0b15d/src/libs/SearchParser/searchParser.js#L276-L280

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

We should parse the keyword filters to remove the extra double quotation marks by using JSON.parse over here to change the line to something like below.

keywords.map((filter) => JSON.parse(filter.right)).flat()

What alternative solutions did you explore? (Optional)

We could remove the extra double quotation marks manually with regex either on this line or after this line.