Skip to content

Escape search query values and resolve typed workspace names - #98522

Open
mukhrr wants to merge 5 commits into
Expensify:mainfrom
mukhrr:fix/98374
Open

Escape search query values and resolve typed workspace names#98522
mukhrr wants to merge 5 commits into
Expensify:mainfrom
mukhrr:fix/98374

Conversation

@mukhrr

@mukhrr mukhrr commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Adds an escape character to the search grammar so a value containing a quote or a comma can be written at all, writes those escapes in sanitizeSearchValue, and resolves a typed workspace name to its ID when exactly one workspace matches. The quote-stripping workarounds from #97083 are removed.

A backslash only escapes what the parser would otherwise consume, so a value already stored in a saved search or a shared URL keeps its current meaning, including one containing a lone backslash.

Submitting a query rebuilds it, and that rebuild used to write a value holding a comma back out bare, so merchant:"Globex,Ltd" returned as two merchants. Every value containing a comma is now quoted. A comma separated list is unaffected, since each value is sanitized on its own.

Values containing a comma, a quote or a backslash therefore serialize differently than before and their query hash changes. Those are exactly the values that do not survive a round trip today.

Fixed Issues

$ #98374
PROPOSAL:

Tests

Setup: create two workspaces named exactly Acme, Inc. and Acme "US",Inc.

  1. Open search (Cmd+K), type type:expense workspace:"Acme, Inc." and press Enter without clicking a suggestion.
    • Verify the URL contains policyID:<the workspace's ID>, not the literal name, and the Workspace filter shows that workspace as selected.
  2. Open search, type type:expense workspace:Acme and click the Acme "US",Inc suggestion.
    • Verify the input reads workspace:"Acme \"US\",Inc" — the full name including quotes, not Acme US,Inc.
    • Press Enter and verify the URL contains that workspace's ID.
  3. Open search, type type:expense workspace:"Acme \"US\",Inc" by hand and press Enter.
    • Verify it resolves to that workspace's ID.
  4. Regression, saved searches: save a search that filters by Acme, Inc., reload, and verify the saved search still loads and still shows as saved.
  5. Regression, a user whose display name contains a quote: type from: and pick them.
    • Verify the input keeps the quotes in their name and the search resolves to their accountID.
  6. Regression, a value that is not resolved to an ID: search merchant:"Globex,Ltd" and press Enter.
    • Verify it stays one merchant rather than becoming two, and that category:Travel,Meals is still treated as two categories.
  • Verify that no errors appear in the JS console

Offline tests

Same as above. Name→ID resolution reads workspaces from Onyx, so it works offline; the search request itself queues as usual.

QA Steps

Same as the Tests section.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android_app.mp4
Android: mWeb Chrome
android.app.mp4
iOS: Native
ios_app.mp4
iOS: mWeb Safari
IOS-web.mp4
MacOS: Chrome / Safari
web.mp4

Two mechanisms handled query values and each dropped something. The grammar had
no way to write a quotation mark, so a workspace or room called `Acme "US",Inc`
could not be expressed and the previous fix silently deleted the quotes. And a
name that was typed rather than picked was never mapped to an ID, so the literal
text went to the server and the search came back empty.

Give the grammar an escape character. A backslash only escapes what the parser
would otherwise consume, so a value already stored in a saved search or a shared
URL keeps the meaning it has today, including one that contains a lone
backslash. Both parsers are regenerated from the shared rules.

Ranges now carry the offset and width of the text each part actually matched.
Walking the parsed values was only correct while a value and its source were the
same length, which escaping breaks, and those ranges position both the
substitutions and the live markdown highlighting.

Write the escapes in sanitizeSearchValue, and resolve a typed workspace name to
its ID when exactly one workspace matches. Names are not unique, so an ambiguous
one is left alone rather than guessing.

With any value now expressible, the quote stripping workarounds are gone.

A comma inside quotes needs no escape, so a value that held one still serializes
byte for byte as before and keeps its query hash. Only a value containing a
quote or a backslash serializes differently, and those are the values that do
not survive a round trip today.
@mukhrr
mukhrr marked this pull request as ready for review August 13, 2026 03:26
@mukhrr
mukhrr requested review from a team as code owners August 13, 2026 03:26
@melvin-bot
melvin-bot Bot requested review from gijoe0295 and trjExpensify August 13, 2026 03:26
@melvin-bot

melvin-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

@gijoe0295 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed request for a team August 13, 2026 03:26
@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

Comment thread src/libs/SearchQueryUtils.ts Outdated
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...c/components/Search/hooks/useUpdateFilterQuery.tsx 50.00% <100.00%> (+3.84%) ⬆️
src/libs/SearchAutocompleteUtils.ts 61.66% <ø> (-1.04%) ⬇️
src/components/Search/SearchAutocompleteList.tsx 92.78% <0.00%> (+0.47%) ⬆️
...onents/Search/SearchPageHeader/SearchPageInput.tsx 78.12% <50.00%> (+0.70%) ⬆️
src/libs/SearchQueryUtils.ts 87.55% <94.73%> (+<0.01%) ⬆️
...rc/components/Search/SearchRouter/SearchRouter.tsx 72.25% <0.00%> (ø)
...omponents/Search/SearchRouter/SearchRouterUtils.ts 83.33% <66.66%> (+0.83%) ⬆️
src/libs/SearchParser/searchParser.js 84.77% <86.60%> (+0.01%) ⬆️
src/libs/SearchParser/autocompleteParser.js 59.34% <79.54%> (-0.34%) ⬇️
... and 8 files with indirect coverage changes

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf92845360

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/SearchQueryUtils.ts Outdated
Comment thread src/libs/SearchQueryUtils.ts Outdated
Submitting a query rebuilds it through buildFilterValuesString, which asked
sanitizeSearchValue not to quote commas. A value that holds one was written back
bare, so `merchant:Acme\,Inc` and `merchant:"Acme,Inc"` both came out as
`merchant:Acme,Inc` and the next read took them as two merchants. The quoted
form was already lost this way before the escape character existed.

Callers pass one value at a time and join them with commas themselves, so a
comma inside a value is always part of it. Quote on it unconditionally and drop
the opt in, which only invited a caller to forget it.

A list of values is unaffected, since each value is sanitized on its own and
only one that contains a comma gains quotes.

Take the display name lookup out of the loop that compares it, justify the
policy subscription, and read ranges back through the typed autocomplete wrapper
so the tests add no assertions.
@mukhrr
mukhrr marked this pull request as draft August 13, 2026 07:18
mukhrr added 2 commits August 13, 2026 13:16
Resolving a typed workspace name read a module level cache filled by its own
Onyx subscription, a second copy of data the callers already hold and one whose
timing nothing guarantees. Take the collection as a parameter instead. Every
caller is a component or a hook that already reads it, so the value now comes
from a subscription that has settled before the render that uses it.

Drop the workspace named with a bare comma from the tests. The remaining cases
still cover a comma inside a value, which is what the quoting is for, under a
name that reads as one workspace rather than two.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c7af07f26

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/SearchQueryUtils.ts
@mountiny
mountiny requested a review from Julesssss August 13, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant