Skip to content

[$250] Tag - No error when creating new tag with existing name when tag name has X: Y format #45067

Closed

Description

@lanitochka17

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.5-5
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4704925
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to Workspace settings > Tag
  3. Add a tag in X: Y format
  4. Click Add tag
  5. Attempt to add the same tag in Step 3
  6. Note that there is no error that the same tag already exists
  7. Create a different tag
  8. Click on the tag in Step 7
  9. Rename it to the same tag in Step 3 and save it
  10. Note that there is no error too and the old tag in Step 7 is gone

Expected Result:

When the tag name has X: Y format, there will be error indicating that the same tag already exists when creating a new tag with the same name (Step 5) and renaming tag to the existing tag name (Step 10)

Actual Result:

When the tag name has X: Y format, no error when creating a new tag with the same name (Step 5) and renaming tag to the same name (Step 10)

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6536532_1720494570528.bandicam_2024-07-09_11-03-34-672.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0126cdffc6828dd304
  • Upwork Job ID: 1811543862318164445
  • Last Price Increase: 2024-07-25
Issue OwnerCurrent Issue Owner: @getusha

Activity

  1. added
    Daily
    Bug
    on Jul 9, 2024
  2. melvin-bot commented on Jul 9, 2024

    @melvin-bot

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

  3. lanitochka17 commented on Jul 9, 2024

    @lanitochka17
    Author

    @mallenexpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

  4. lanitochka17 commented on Jul 9, 2024

    @lanitochka17
    Author

    We think that this bug might be related to #wave-collect - Release 1

  5. bernhardoj commented on Jul 9, 2024

    @bernhardoj
    Contributor

    Proposal

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

    There is no tag existing error when trying to add or edit a tag in X: Y format.

    What is the root cause of that problem?

    When we add a tag in X: Y format, the colon (:) is escaped, so it becomes X\: Y. When we check whether there is an existing tag, we just use the tag name input from the user without escaping it.

    } else if (tags?.[tagName]) {
    errors.tagName = translate('workspace.tags.existingTagError');

    For example, if we input a: b, the tag will be saved as a\: b. When we try to add a: b again, it will check if a: b exists or not which doesn't.

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

    Escape the tag name before doing the comparison.

    const tagName = values.tagName.trim();
    const {tags} = PolicyUtils.getTagList(policyTags, 0);
    if (!ValidationUtils.isRequiredFulfilled(tagName)) {
    errors.tagName = translate('workspace.tags.tagRequiredError');
    } else if (tags?.[tagName]) {
    errors.tagName = translate('workspace.tags.existingTagError');

    PolicyUtils.escapeTagName(values.tagName.trim())

    We need to do the same for edit tag page.

    Also, there is another issue where adding x:y and x\:y tags will show both tags as x:y in the tag list, confusing the user. It's because the code replaces \: or \\: with : from the tag name.

    App/src/libs/PolicyUtils.ts

    Lines 289 to 291 in 9cd3257

    function getCleanedTagName(tag: string) {
    return tag?.replace(/\\{1,2}:/g, CONST.COLON);
    }

    To fix it, we only want to replace \: with :.
    tag?.replace(/\\:/g, CONST.COLON);

  6. devguest07 commented on Jul 9, 2024

    @devguest07
    Contributor

    Proposal

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

    No error when creating new tag with existing name when tag name has X: Y format

    What is the root cause of that problem?

    When a new tag is added and the tag string contain a colon : the backend will store it on Onyx adding a \ before the colon. So when we add a new tag that contain a colon, we need to check if it exist in the Onyx value. The issue is that the tags on Onyx has a \ added. And currently we are not checking the new tag with the \ similar to what we have stored on Onyx.

    We have a function escapeTagName that takes a tag string with : and add the \ to make it similar to the Onyx values. We can use it in the comparisation.

    function escapeTagName(tag: string) {

    Below a table with some tests I have done:

    • Input: is the value entered on the input form when addinga new tag
    • Onyx: how the new tag will be stored on the database
    • Escaped: the input value passed throw the escapeTagName function
    • Displayed: how the value will be displayed for the user on the tags list page
    Test Input Onyx Escaped Displayed
    1 a: a a\: a a\: a a: a
    2 b\: b b\\: b b\\: b b: b
    3 c\\: c c\\\: c c\\\: c c\: c
    4 d\\\: d d\\\\: d d\\\\: d d\\: d

    On Test 1, if the user type something in the form of X: Y we can use the escapeTagName to make sure we don't get a duplicate, as we notice from the table, the Onyx value is equal to the Escaped value, same for the input value and the displayed value. So, X: Y will not be repeated.

    But on Test 3, if the user type when adding a new tag c\\: c the displayed value will be different. Comparing the escapeTagName with the Onyx value will show that the value already exist but it doesn't. Because the displayed value is not as the one on the input, it's different value c\: c.

    So, as we notice, using escapeTagName to compare the Onyx value with the new tag is correct is just some cases where the new tag string have only a colon, but when the user use a colon and lore than a \ in the new tag value , the comparisation using escapeTagName will not be correct. The error will display that those new tag already exists but it doesn't.

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

    As mentioned, using escapeTagName to compare the Onyx value with the new tag value will solve only some cases like Test 1 and Test 2, but in more complex examples like Test 3 and Test 4, the comparisation using escapeTagName will display wrong results.

    To make a fair comparisation between the value of the new tag and the one displayed using values from Onyx, we should follow a better path. One way to do that is by:

    1. Take all the tags from Onyx and convert those values to an array with value similar to the tags displayed
      policyTags: OnyxEntry<PolicyTagList>;

    As we do for the display, we can use getCleanedTagName to make sure we have the same values as displayed on the tags page.

    text: PolicyUtils.getCleanedTagName(tag.name),

    1. Compare the new tag string to the new tags array:
      Now we have a new array with the same values displayed, we can compare the entered new tag string with those values and make sure no value will be similar to the one from the input.
      } else if (tags?.[tagName]) {

    What alternative solutions did you explore?

  7. added
    External
    on Jul 11, 2024
  8. changed the title [-]Tag - No error when creating new tag with existing name when tag name has X: Y format[/-] [+][$250] Tag - No error when creating new tag with existing name when tag name has X: Y format[/+] on Jul 11, 2024
  9. melvin-bot commented on Jul 11, 2024

    @melvin-bot
  10. added
    Help Wanted
    on Jul 11, 2024
  11. melvin-bot commented on Jul 11, 2024

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @getusha (External)

  12. 49 remaining items

  13. mallenexpensify commented on Aug 26, 2024

    @mallenexpensify
    Contributor

    @bernhardoj, @getusha can you provide and update on where we're at here? I think payment is due now cuz the second PR hit production over a week ago.

    And, with/for the first PR, I see

    We've been saving tag name by escaping it before this PR, so this PR didn't cause it.

    So that doesn't seems like it was a regression.

  14. bernhardoj commented on Aug 26, 2024

    @bernhardoj
    Contributor

    @mallenexpensify yes, I believe it's now ready for payment.

    So that doesn't seems like it was a regression.

    Correct.

  15. mallenexpensify commented on Aug 26, 2024

    @mallenexpensify
    Contributor

    Contributor: @bernhardoj due $250 via NewDot
    Contributor+: @getusha due $250 via NewDot

    @getusha we want a regression test here, right? Assuming so, plz complete the BZ checklist below. Thx

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@] The PR that introduced the bug has been identified. Link to the PR:
    • [@] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@] Determine if we should create a regression test for this bug.
    • [@] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@bz] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
    • [ ]
  16. techievivek commented on Aug 29, 2024

    @techievivek
    Contributor

    Gentle bump @getusha on above.

  17. techievivek commented on Aug 29, 2024

    @techievivek
    Contributor

    Not overdue.

  18. getusha commented on Aug 29, 2024

    @getusha
    Contributor

    [@] The PR that introduced the bug has been identified. Link to the PR: I wouldn't call this a regression at it seems to be an edge case that must've been missed on feature implementation.
    [@] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: N/a
    [@] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: N/a
    [@] Determine if we should create a regression test for this bug. Yes
    [@] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

    Regression Test Proposal

    1. Open the app
    2. Go to Workspace settings > Tag
    3. Add X:Y tag
    4. Attempt to add the same tag X:Y
    5. Verify A tag with this name already exists error appears
    6. Add a different tag
    7. Click on the tag in Step 6
    8. Rename it to the same tag in Step 3 (X:Y) and save it
    9. Verify A tag with this name already exists error appears

    Do we agree 👍 or 👎

  19. techievivek commented on Aug 30, 2024

    @techievivek
    Contributor

    Looks good, @mallenexpensify let's get it added to testRail, thanks.

  20. bernhardoj commented on Aug 30, 2024

    @bernhardoj
    Contributor

    Requested in ND.

  21. JmillsExpensify commented on Aug 30, 2024

    @JmillsExpensify
    Contributor

    $250 approved for @bernhardoj

  22. mallenexpensify commented on Aug 30, 2024

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

Metadata

Metadata

Labels

BugDailyExternal

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions