Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removing extra pair of quotes in keyword filter #53158

Merged
merged 10 commits into from
Dec 30, 2024

Conversation

Tony-MK
Copy link
Contributor

@Tony-MK Tony-MK commented Nov 26, 2024

Explanation of Change

This PR removes the extra pair of double quotation marks wrapped around keywords that contain special characters to prevent the keywords from being wrapped continuously after every search.

Fixed Issues

$ #52923
PROPOSAL: #52923 (comment)

Tests

  1. Go to search.
  2. Click "Filters".
  3. Click "Has Keywords".
  4. Enter the link as a keyword.
  5. Click on "Save".
  6. Click "View Results".
  7. Verify that the keyword is wrapped with double quotation marks.
  8. Switch tabs numerously to verify that the keyword doesn't get wrapped in extra double quotation marks.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

Same as tests

  • 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
    • MacOS: Desktop
  • 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 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 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.-.Native.webm
Android: mWeb Chrome
Android.-.mWeb.webm
iOS: Native
iOS.-.Native.mp4
iOS: mWeb Safari
iOS.-.mWeb.mp4
MacOS: Chrome / Safari
MacOS.-.Chrome.mov
MacOS: Desktop
MacOS.-.Desktop.mov

@Tony-MK Tony-MK requested a review from a team as a code owner November 26, 2024 18:35
@melvin-bot melvin-bot bot requested review from hungvu193 and removed request for a team November 26, 2024 18:35
Copy link

melvin-bot bot commented Nov 26, 2024

@hungvu193 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]

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 26, 2024

I noticed a regression with my proposal when entering keywords which are already wrapped in double quotation marks.

Hence, I deviated from the original proposal and found a better solution.

Should I update my proposal for clafications?

@hungvu193
Copy link
Contributor

hungvu193 commented Nov 27, 2024

Should I update my proposal for clafications?

Yes, please. If you decided to update the regex, What makes your regex better than the first contributor's proposal?

Which regression did you find?

@hungvu193
Copy link
Contributor

little bump @Tony-MK

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 29, 2024

Should I update my proposal for clarifications?

Yes, please. If you decided to update the regex, What makes your regex better than the first contributor's proposal?

Just updated my proposal and it changes the regex to consider the colon as not a special character.

Which regression did you find?

I found a regression when you enter a keyword with quotation marks the app would not allow me to save the search and on pressing view results, the app shows the not found page.

Regression.mov

@hungvu193
Copy link
Contributor

What makes your regex better than the first contributor's proposal?

How about the second part here?

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 29, 2024

What makes your regex better than the first contributor's proposal?

How about the second part here?

Oh, both of the regexes are wrong because they will cause a regression where the keywords don't give search results when known results are present.

This is because the keyword is already wrapped and the colon is a special character used to split the search type and value. E.g. type: all.

So, the regex we currently use is correct and should not be changed.

However, after investigating the regressions, I noticed that we should remove only one pair of quotes, the first and last quotation marks, from filter.right like how the JSON.parse function does but manually with slice and a custom regex.

keywords.map((filter) => 
    /^".*"$/g.test(filter.right) ? 
    filter.right.slice(1, - 1) : 
    filter.right
).flat()

Do you have any thoughts about the explanation?

@hungvu193
Copy link
Contributor

Thanks, can you also add unit tests for this case so we won't face it again?

@hungvu193
Copy link
Contributor

Little bump on the comment above @Tony-MK

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 3, 2024

Thanks, can you also add unit tests for this case so we won't face it again?

I have added more tests, kindly check.

Thanks

@Tony-MK Tony-MK changed the title fix: adding a colon to the regex parser to sanitize link fix: removing extra pair of quotes in keyword filter Dec 3, 2024
@hungvu193
Copy link
Contributor

Thanks for your update. I'll check it today!

@hungvu193
Copy link
Contributor

I think it failed the first testcase, please check the video below:

Screen.Recording.2024-12-04.at.10.32.58.mov

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 5, 2024

I think it failed the first testcase, please check the video below:

Screen.Recording.2024-12-04.at.10.32.58.mov

You included the single quotation marks (') wrapping the query.

If you remove them, '" " " "' -> " " " ", this should work nicely.

@hungvu193
Copy link
Contributor

If you see in the video, the search query in the first tab is different with other tabs

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 5, 2024

I tried testing some queries wrapped in single quotes.

I noticed it removes the inner double quotation marks for double-quoted whitespaces in queries that are wrapped in single quotes into a one-space character wrapped in single quotations, ' ', Eg:

a) One whitespace : '" "' -> ' ' -> ' '
b) Three whitespaces : '" " " "' -> ' ' -> ' '

It is similar to how queries with empty whitespaces wrapped in single quotes are handled, Eg: ' ' -> ' '.

This doesn't affect queries with characters and if you replace the whitespaces with characters, Eg: '" "' -> '"https://expensify.com"', it won't occur.

Well, let me know if this is an edge case worth fixing since it only involves searching a precise pattern of empty whitespaces.

@hungvu193
Copy link
Contributor

The problem here is the inconsistency when switching between the filter tab

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 6, 2024

I updated the regex. Check if the problem persists.

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 7, 2024

Please update the screenshots/video based on your new changes

I retested the changes and updated the videos.

make sure the original issue + the issue I commented above don't appear.

I am not sure what you meant.

Can you explain further?

@hungvu193
Copy link
Contributor

@Tony-MK I think we're still facing the same issue. Please look at the video below:

Screen.Recording.2024-12-09.at.13.47.47.mov

I'm still seeing extra " was added into our string.

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 10, 2024

Can you give the steps to replicate this issue?

I tried to replicate it but failed.

Screen.Recording.2024-12-10.at.10.08.16.mov

@hungvu193
Copy link
Contributor

I think in the above video that you posted when you enter "https://facebook.com" and press Save Search, the filter text returned ""https://facebook.com""which had extra doule quote mark.

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 13, 2024

I think in the above video that you posted when you enter "https://facebook.com" and press Save Search, the filter text returned ""https://facebook.com""which had extra doule quote mark.

Yeah, but it only adds double quotes, not more than that.

That's by design.

The sanitizeSearchValue function will add the extra double quotes if the keyword already has special characters, and then searchParser.parse will remove them.

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

It's like how http://facebook.com returns "http://facebook.com".

Therefore, "http://facebook.com" returns ""http://facebook.com"".

@hungvu193
Copy link
Contributor

Therefore, "http://facebook.com" returns ""http://facebook.com"".

Hmm, I'm afraid I have to disagree with you at this point, if our keyword's already wrapped inside ", I think we shouldn't add ".

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Dec 16, 2024

Hmm, I'm afraid I have to disagree with you at this point, if our keyword's already wrapped inside ", I think we shouldn't add "

That's okay, I understand.

However, I am a bit scared that search regressions will arise like getting unexpected or no search results, since the double quote is specifically used in the regex in sanitizeSearchValue to wrap any keyword with special characters even if has it has double quotes itself.

sanitizeSearchValue

WDYT?


Nevertheless, before I push the new changes, I would like to ensure that this is an issue I need to correct.

After saving or viewing the results, if you entered a link that is already wrapped once, "https://google.com", on the filters page, the keyword is displayed as https://google.com without the double quotes instead of "https://google.com".

Hence, a user can not search for the exact keyword if it has a single pair of double quotes wrapping it such as "https://google.com" because it will change to https://google.com and are treated as identical keywords.

Screen.Recording.2024-12-16.at.13.55.30.mov

@hungvu193
Copy link
Contributor

Thanks for your update. I'll take a look today!

@hungvu193
Copy link
Contributor

Look like serrver is down, I can't test it atm

@hungvu193
Copy link
Contributor

Nevertheless, before I push the new changes, I would like to ensure that this is an issue I need to correct.

After saving or viewing the results, if you entered a link that is already wrapped once, "https://google.com", on the filters page, the keyword is displayed as https://google.com without the double quotes instead of "https://google.com".

Hence, a user can not search for the exact keyword if it has a single pair of double quotes wrapping it such as "https://google.com" because it will change to https://google.com and are treated as identical keywords.

After taking tests, I agree with you at this point

@hungvu193
Copy link
Contributor

@Tony-MK Can you merge main please?

@hungvu193
Copy link
Contributor

hungvu193 commented Dec 25, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Screen.Recording.2024-12-25.at.13.52.19.mov
Android: mWeb Chrome
androidmandroid.mov
iOS: Native
Screen.Recording.2024-12-25.at.13.44.11.mov
iOS: mWeb Safari
Screen.Recording.2024-12-25.at.13.46.29.mov
MacOS: Chrome / Safari
Chrome.mov
MacOS: Desktop
Desk.mov

@melvin-bot melvin-bot bot requested a review from srikarparsi December 25, 2024 06:53
@srikarparsi
Copy link
Contributor

Hey, I'll take a look at this tomorrow

Copy link
Contributor

@srikarparsi srikarparsi left a comment

Choose a reason for hiding this comment

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

lgtm thanks for the tests :)

@srikarparsi srikarparsi merged commit 483d287 into Expensify:main Dec 30, 2024
16 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

Copy link
Contributor

🚀 Deployed to staging by https://github.com/srikarparsi in version: 9.0.80-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 success ✅
🍎🔄 iOS HybridApp 🍎🔄 success ✅

Copy link
Contributor

github-actions bot commented Jan 6, 2025

🚀 Deployed to production by https://github.com/puneetlath in version: 9.0.80-6 🚀

platform result
🤖 android 🤖 true ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 failure ❌
🍎🔄 iOS HybridApp 🍎🔄 success ✅

@hungvu193
Copy link
Contributor

just realized we shouldn't update searchParser.js file, we should update searchParser.peggy instead. Since searchParser.js is generated by searchParser.peggyfile.
@Tony-MK Can you raise a PR to fix it?

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Jan 15, 2025

@hungvu193, What about the keyword tests?

They will fail so where should move them?

@hungvu193
Copy link
Contributor

@hungvu193, What about the keyword tests?

They will fail so where should move them?

You will need to regenerate searchParser.js file if you changed peggy file. So our tests wont be failed

@hungvu193
Copy link
Contributor

We have the command to generate searchParser.js in our package.json

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Jan 15, 2025

Thanks

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Jan 15, 2025

I opened the PR.

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.

4 participants