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

[HOLD for payment 2023-08-28] [$1000] Triple clicking text and copying to clipboard results in text copied containing button text #24156

Closed
1 of 6 tasks
kavimuru opened this issue Aug 4, 2023 · 37 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kavimuru
Copy link

kavimuru commented Aug 4, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. From user A, go to the chat with user B
  2. From user B, send a message
  3. From user A, Flag the message as violating
  4. Click triple to the hidden message
  5. Click the right pointer to open the context menu > Choose Copy to clipboard
  6. Past this into the composer and notice the message copied

Expected Result:

The message copied shouldn't contain reveal button text

Actual Result:

The message copied contains reveal button text

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.50-1
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

Screen.Recording.2023-08-01.at.17.19.37.mov
Recording.1445.mp4

Expensify/Expensify Issue URL:
Issue reported by: @dukenv0307
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1690886867471159

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~012ab20f2847f765d5
  • Upwork Job ID: 1688571815431098368
  • Last Price Increase: 2023-08-07
  • Automatic offers:
    • bernhardoj | Contributor | 26116127
    • dukenv0307 | Reporter | 26116129
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 4, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 4, 2023

Triggered auto assignment to @greg-schroeder (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Aug 4, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@ygshbht
Copy link
Contributor

ygshbht commented Aug 4, 2023

Proposal

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

The issue is that when triple-clicking a hidden message and copying it to the clipboard, the copied text includes parts of the message that are not intended to be copied.

What is the root cause of that problem?

The issue occurs because of how the text selection is currently handled in the code. It's set to copy the selected text over the message text.

onPress: (closePopover, {reportAction, selection}) => {
const isReportPreviewAction = ReportActionUtils.isReportPreviewAction(reportAction);
const message = _.last(lodashGet(reportAction, 'message', [{}]));
const messageHtml = lodashGet(message, 'html', '');
const isAttachment = _.has(reportAction, 'isAttachment') ? reportAction.isAttachment : ReportUtils.isReportMessageAttachment(message);
if (!isAttachment) {
const content = selection || messageHtml;
if (isReportPreviewAction) {

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

To fix this, we need to modify how the selection is handled. Specifically, we should ensure that only the user-generated message text can be selected, not any additional UI text or elements. Based on preference, candition can be modified like
const content = messageHtml;

@bernhardoj
Copy link
Contributor

Proposal

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

Triple-click the hidden message explanation will also copy the Reveal Message button text even though it's not selectable.

What is the root cause of that problem?

This issue is very similar to #18343 and #17838. When we triple-click, it will select the text and the text near it, in this case, the reveal message button. The reveal message button text itself is not selectable, but it's the browser bug that makes the non-selectable text gets copied too.

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

We can apply the same solution from both issues above, that is to add
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
to the reveal button text, so it will be excluded when we copy the text.

@melvin-bot melvin-bot bot added the Overdue label Aug 7, 2023
@pbkompasz
Copy link

pbkompasz commented Aug 7, 2023

Proposal

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

Triple click to text and copy to clipborad the text copied contains button text

What is the root cause of that problem?

  1. The <Text /> element is missing the selectable prop.
  2. The SelectionScraper returns a new string from the DOM. In this case we could remove the unwanted elements i.e. 'Hide messages' < Text/>

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

Add selectable prop to <Text />

// Text.js
const propTypes = {
    // ...

    /** Should we make this selectable */
    selectable: PropTypes.boolean,
};

const defaultProps = {
    // ...
    selectable: true,
};

// ReportActionItem.js
<Text
  style={styles.buttonSmallText}
  selectable={false}
>
  {isHidden ? props.translate('moderation.revealMessage') : props.translate('moderation.hideMessage')}
</Text>

The getCurrentSelection method in SelectionScraper could receive an option to ignore the selectable===false elements.
In the replaceNodes we can remove these nodes

const replaceNodes = (dom, isChildOfEditorElement) => {

What alternative solutions did you explore? (Optional)

When copying a message without the selection the button's text doesn't get copied.
Similarly when selecting the whole message we should get the same result.
Given this we could treat this as an edge case in

onPress: (closePopover, {reportAction, selection}) => {
const isReportPreviewAction = ReportActionUtils.isReportPreviewAction(reportAction);
const message = _.last(lodashGet(reportAction, 'message', [{}]));
const messageHtml = lodashGet(message, 'html', '');

// Check if selection contains the whole message (different implementation)
if (selection >= message) {
  selection = messageHtml;
}

@greg-schroeder greg-schroeder added the External Added to denote the issue can be worked on by a contributor label Aug 7, 2023
@melvin-bot melvin-bot bot changed the title Triple click to text and copy to clipborad the text copied contains button text [$1000] Triple click to text and copy to clipborad the text copied contains button text Aug 7, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

Job added to Upwork: https://www.upwork.com/jobs/~012ab20f2847f765d5

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 7, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

Current assignee @greg-schroeder is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

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

@greg-schroeder greg-schroeder changed the title [$1000] Triple click to text and copy to clipborad the text copied contains button text [$1000] Triple clicking text and copying to clipboard results in text copied containing button text Aug 7, 2023
@greg-schroeder
Copy link
Contributor

Reproduced

@melvin-bot melvin-bot bot removed the Overdue label Aug 7, 2023
@swakeert
Copy link

swakeert commented Aug 7, 2023

Proposal

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

When selecting a reported message that has been hidden, the "Reveal Message" text and any emoji reactions are also getting copied.

What is the root cause of that problem?

Since the error is also reproducible when using Ctrl + C, I was able to rule out anything to do with the Copy action inside the Context Menu.

This code overloads the Ctrl + C shortcut and uses the SelectionScraper to fill the clipboard.

const selection = SelectionScraper.getCurrentSelection();

And after extensive digging into the code, I believe this line is the problem:

const divsToRemove = div.querySelectorAll(`[data-${CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT}=true]`);

The SelectionScraper eliminates the data-selection-scrapper-hidden-element="true" items, but this is true only on hover. I still need to find where else is the true and false being manipulated. In the React code, it is manipulated by the following code, but I need to follow the chain to see where it is initially set and why:
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}

The initial implementation of UnreadActionIndicator is probably the root cause of where this problem first showed up.

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

A simple and quick bug fix will be to remove data-selection-scrapper-hidden-element elements irrespective of whether it is true or false. But that will lead to unnecessary side effects, as happened with #17838 and #18343.

A long-term solution is to identify where the selection-scrapper-hidden-element is being added, why and what all code is manipulating it. A catch-all removal is not a sufficient solution.

What alternative solutions did you explore? (Optional)

I looked at all the Context Menu code, the ExpensiMark code and the parsing code. Since the error was exactly reproducible when using the keyboard shortcut, it meant the context menu code was not the issue.
Also, the browser could not be at fault for the copy functionality as it is overwritten for both the mouse and keyboard. The user-select: none is working as expected on the browser

@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

📣 @swakeert! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  2. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  3. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@swakeert
Copy link

swakeert commented Aug 7, 2023

Contributor details
Your Expensify account email: swakeert@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/swakeertjain

@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

@narefyev91
Copy link
Contributor

Proposal from @bernhardoj looks good to me #24156 (comment) - we already have the same fixes for other situations which are closely to this one. Let's fix it in the same manner
🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

Triggered auto assignment to @jasperhuangg, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@ygshbht
Copy link
Contributor

ygshbht commented Aug 8, 2023

Proposal from @bernhardoj looks good to me #24156 (comment) - we already have the same fixes for other situations which are closely to this one. Let's fix it in the same manner 🎀 👀 🎀 C+ reviewed

@narefyev91 Pardon me if this seems naive or if I'm asking something obvious. The issue arises when you select text and then copy it by right-clicking; it copies the selection instead of the original hidden message. The expected result is that it should copy the user's message. Hence, I suggested we prioritize copying the user's message, or if preferred, only do so in flagged cases. If I understand correctly, @bernhardoj suggests that users shouldn't be able to select text at all. So, is that what you're proposing: to prevent users from selecting text in the first place?

@bernhardoj
Copy link
Contributor

The button text itself is already unselectable

<Text
style={styles.buttonSmallText}
selectable={false}
>
{isHidden ? props.translate('moderation.revealMessage') : props.translate('moderation.hideMessage')}
</Text>

but you can still copy it by triple-clicking the text near it or dragging the selection over the button text

@melvin-bot melvin-bot bot added the Overdue label Aug 10, 2023
@swakeert
Copy link

swakeert commented Aug 11, 2023

@bernhardoj did you try using ctrl+C to copy? It is still copying the same text. I have checked everything and am convinced this is not a browser bug nor an issue with user-select. It happens even when my mouse goes nowhere near the reveal message button.

It is an issue with the selection function and what it decided to omit.
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}} This is a good fix, but we can't keep applying it to every component, every time there is a select, non-select disparity and we should respect the user-select CSS in the selection function.

EDIT: can't instead of can.

@melvin-bot melvin-bot bot removed the Overdue label Aug 14, 2023
@jasperhuangg
Copy link
Contributor

Apologies for the delay! I agree that we should go with @bernhardoj's solution, it seems like it closely mirrors solutions we have implemented for this problem in other places.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 14, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 14, 2023

📣 @bernhardoj 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot
Copy link

melvin-bot bot commented Aug 14, 2023

📣 @dukenv0307 🎉 An offer has been automatically sent to your Upwork account for the Reporter role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@bernhardoj
Copy link
Contributor

PR is ready
cc: @narefyev91

@melvin-bot
Copy link

melvin-bot bot commented Aug 15, 2023

🎯 ⚡️ Woah @narefyev91 / @bernhardoj, great job pushing this forwards! ⚡️

The pull request got merged within 3 working days of assignment, so this job is eligible for a 50% #urgency bonus 🎉

  • when @bernhardoj got assigned: 2023-08-14 16:48:54 Z
  • when the PR got merged: 2023-08-15 20:05:08 UTC

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Aug 21, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Triple clicking text and copying to clipboard results in text copied containing button text [HOLD for payment 2023-08-28] [$1000] Triple clicking text and copying to clipboard results in text copied containing button text Aug 21, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Aug 21, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.55-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-08-28. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

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:

  • [@narefyev91] The PR that introduced the bug has been identified. Link to the PR:
  • [@narefyev91] 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:
  • [@narefyev91] 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:
  • [@narefyev91] Determine if we should create a regression test for this bug.
  • [@narefyev91] 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.
  • [@greg-schroeder] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@narefyev91
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: No PR caused regression. This issue always existed as this is the default behavior of browser selection & copy to clipboard.
  • 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 - no needs any tests in case it's not a regression

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 Daily KSv2 labels Aug 28, 2023
@greg-schroeder
Copy link
Contributor

Thanks @narefyev91 - today is payment date so working through that now.

@greg-schroeder
Copy link
Contributor

greg-schroeder commented Aug 29, 2023

Issue Participants:

Issue reported by: @dukenv0307
Contributor: @bernhardoj
C+: @narefyev91

Was this issue merged in time to be eligible for the speed bonus? Yes
Were their any regressions? No

Payment summary:

Reporter: $250
Contributor: $1500
C+: $1500 (not applicable)

@greg-schroeder
Copy link
Contributor

Payments made, checklist complete. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

8 participants