App icon indicating copy to clipboard operation
App copied to clipboard

fix: removing extra pair of quotes in keyword filter

Open Tony-MK opened this issue 1 year ago • 19 comments

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

$ https://github.com/Expensify/App/issues/52923 PROPOSAL: https://github.com/Expensify/App/issues/52923#issuecomment-2492749621

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.
  • [x] 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

  • [x] Verify that no errors appear in the JS console

PR Author Checklist

  • [x] I linked the correct issue in the ### Fixed Issues section above
  • [x] I wrote clear testing steps that cover the changes made in this PR
    • [x] I added steps for local testing in the Tests section
    • [x] I added steps for the expected offline behavior in the Offline steps section
    • [x] I added steps for Staging and/or Production testing in the QA steps section
    • [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [x] 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)
    • [x] 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).
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I ran the tests on all platforms & verified they passed on:
    • [x] Android: Native
    • [x] Android: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb Safari
    • [x] MacOS: Chrome / Safari
    • [x] MacOS: Desktop
  • [x] 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)
  • [x] I followed proper code patterns (see Reviewing the code)
    • [x] 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)
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] 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.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • [x] 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:
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] 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)
    • [x] 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.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I followed the guidelines as stated in the Review Guidelines
  • [x] 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)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] 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
  • [x] I verified that if a function's arguments changed that all usages have also been updated correctly
  • [x] If any new file was added I verified that:
    • [x] 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
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • [x] 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.
  • [x] 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)
  • [x] 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.
  • [x] 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.
  • [x] 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:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [x] 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.
  • [x] I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • [x] 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

https://github.com/user-attachments/assets/ae0092e4-a0fa-4b01-9c67-a292c4ff973d

iOS: mWeb Safari

https://github.com/user-attachments/assets/75249114-a490-4c5f-a1a2-da2ed5fafe5c

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/43f02b55-fba7-400a-9b3b-ee33bb055d15

MacOS: Desktop

https://github.com/user-attachments/assets/e8885c75-81ed-43bc-8986-e305e0f4deec

Tony-MK avatar Nov 26 '24 18:11 Tony-MK

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

melvin-bot[bot] avatar Nov 26 '24 18:11 melvin-bot[bot]

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?

Tony-MK avatar Nov 26 '24 21:11 Tony-MK

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 avatar Nov 27 '24 02:11 hungvu193

little bump @Tony-MK

hungvu193 avatar Nov 29 '24 02:11 hungvu193

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.

https://github.com/user-attachments/assets/6d4fed2c-199e-4d1f-af45-b3cfba33144e

Tony-MK avatar Nov 29 '24 10:11 Tony-MK

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

How about the second part here?

hungvu193 avatar Nov 29 '24 13:11 hungvu193

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?

Tony-MK avatar Nov 29 '24 17:11 Tony-MK

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

hungvu193 avatar Nov 30 '24 08:11 hungvu193

Little bump on the comment above @Tony-MK

hungvu193 avatar Dec 03 '24 02:12 hungvu193

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 avatar Dec 03 '24 19:12 Tony-MK

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

hungvu193 avatar Dec 04 '24 02:12 hungvu193

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

https://github.com/user-attachments/assets/62a0efd0-cf2d-4366-ba1c-2180ab65530f

hungvu193 avatar Dec 04 '24 03:12 hungvu193

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.

Tony-MK avatar Dec 05 '24 17:12 Tony-MK

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

hungvu193 avatar Dec 05 '24 17:12 hungvu193

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.

Tony-MK avatar Dec 05 '24 18:12 Tony-MK

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

hungvu193 avatar Dec 06 '24 01:12 hungvu193

I updated the regex. Check if the problem persists.

Tony-MK avatar Dec 06 '24 02:12 Tony-MK

Please update the screenshots/video based on your new changes and make sure the original issue + the issue I commented above don't appear. Test it carefully before requesting a re-review. Thanks.

hungvu193 avatar Dec 06 '24 02:12 hungvu193

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?

Tony-MK avatar Dec 07 '24 21:12 Tony-MK

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

https://github.com/user-attachments/assets/3ea91f1e-c60e-4d4a-8d12-d4a48bf7e55d

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

hungvu193 avatar Dec 09 '24 07:12 hungvu193

Can you give the steps to replicate this issue?

I tried to replicate it but failed.

https://github.com/user-attachments/assets/f2ca26d5-d5b0-48f4-99b2-7495fa8c3b07

Tony-MK avatar Dec 10 '24 09:12 Tony-MK

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.

hungvu193 avatar Dec 10 '24 15:12 hungvu193

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.

https://github.com/Expensify/App/blob/7be9987ce91638600b5f61c8652c50517c2ca001/src/libs/SearchQueryUtils.ts#L39-L42

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

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

Tony-MK avatar Dec 13 '24 00:12 Tony-MK

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 ".

hungvu193 avatar Dec 15 '24 07:12 hungvu193

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.

https://github.com/user-attachments/assets/4a73277f-f085-45b0-89e4-a6a24d23f1f9

Tony-MK avatar Dec 16 '24 11:12 Tony-MK

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

hungvu193 avatar Dec 17 '24 11:12 hungvu193

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

hungvu193 avatar Dec 19 '24 08:12 hungvu193

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 avatar Dec 25 '24 06:12 hungvu193

@Tony-MK Can you merge main please?

hungvu193 avatar Dec 25 '24 06:12 hungvu193

Reviewer Checklist

  • [x] I have verified the author checklist is complete (all boxes are checked off).
  • [x] I verified the correct issue is linked in the ### Fixed Issues section above
  • [x] I verified testing steps are clear and they cover the changes made in this PR
    • [x] I verified the steps for local testing are in the Tests section
    • [x] I verified the steps for Staging and/or Production testing are in the QA steps section
    • [x] 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)
    • [x] 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)
  • [x] I checked that screenshots or videos are included for tests on all platforms
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I verified tests pass on all platforms & I tested again on:
    • [x] Android: Native
    • [x] Android: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb Safari
    • [x] MacOS: Chrome / Safari
    • [x] MacOS: Desktop
  • [x] 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
  • [x] I verified proper code patterns were followed (see Reviewing the code)
    • [x] 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).
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] 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.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] 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)
    • [x] 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.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I verified that this PR follows the guidelines as stated in the Review Guidelines
  • [x] 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)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] 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
  • [x] If a new component is created I verified that:
    • [x] A similar component doesn't exist in the codebase
    • [x] All props are defined accurately and each prop has a /** comment above it */
    • [x] The file is named correctly
    • [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • [x] The only data being stored in the state is data necessary for rendering and nothing else
    • [x] 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)
    • [x] 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)
    • [x] All JSX used for rendering exists in the render method
    • [x] 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
  • [x] If any new file was added I verified that:
    • [x] 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
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • [x] 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.
  • [x] 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)
  • [x] 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.
  • [x] 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.
  • [x] 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:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [x] 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.
  • [x] For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • [x] 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.
  • [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native

https://github.com/user-attachments/assets/d47760ee-1e03-4539-94bb-7cc808624e6a

Android: mWeb Chrome

https://github.com/user-attachments/assets/5e4c5abc-dbb7-4d17-8533-d678f54baa99

iOS: Native

https://github.com/user-attachments/assets/77878bcd-3fc7-4dfb-a2bc-fcff47cb4d08

iOS: mWeb Safari

https://github.com/user-attachments/assets/fab0adf5-2346-4365-abd5-f118d0f05691

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/9a00735b-ac66-4bee-818b-23d2c115b608

MacOS: Desktop

https://github.com/user-attachments/assets/a85e39ae-3594-485c-97f8-17cc62bc0df7

hungvu193 avatar Dec 25 '24 06:12 hungvu193