Skip to content

[HOLD for payment 2023-08-30] [$1000] Web - Markdown pasted from selection-copy is different from clipboard-copy #23659

Closed

Description

@kbecciv

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. Open any report
  2. Paste this markdown (it has a heading, then a code snippet and a quote)

test heading

Code snippet

link

  1. Now use the copy to clipboard option, and copy the sent message
  2. Paste the message in the composer and send it again (notice that there are no difference in both messages)
  3. Now select the sent message text by cursor and press cmd+c
  4. Paste the text in the composer and send the message.
  5. Notice that the markdown message has an extra line in the code snippet part.

Expected Result:

Message copied from selection should be the same that that copied from context menu

Actual Result:

Message copied from selection has an extra line

Workaround:

Unknown

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.45-8
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-07-26.at.2.34.29.PM.mp4
Recording.3922.mp4

Expensify/Expensify Issue URL:
Issue reported by: @huzaifa-99
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1690364432300409

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~019c94943755b5fa6d
  • Upwork Job ID: 1684694244929720320
  • Last Price Increase: 2023-08-03
  • Automatic offers:
    • mollfpr | Reviewer | 26012873
    • huzaifa-99 | Reporter | 26012875

Activity

  1. added
    Daily
    Bug
    on Jul 26, 2023
  2. melvin-bot commented on Jul 26, 2023

    @melvin-bot

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

  3. melvin-bot commented on Jul 26, 2023

    @melvin-bot

    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
  4. added
    External
    on Jul 27, 2023
  5. changed the title [-]Web - Markdown pasted from selection-copy is different from clipboard-copy[/-] [+][$1000] Web - Markdown pasted from selection-copy is different from clipboard-copy[/+] on Jul 27, 2023
  6. melvin-bot commented on Jul 27, 2023

    @melvin-bot
  7. added
    Help Wanted
    on Jul 27, 2023
  8. melvin-bot commented on Jul 27, 2023

    @melvin-bot

    Current assignee @puneetlath is eligible for the External assigner, not assigning anyone new.

  9. melvin-bot commented on Jul 27, 2023

    @melvin-bot

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

  10. akamefi202 commented on Jul 28, 2023

    @akamefi202
    Contributor

    Proposal

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

    An extra line is added to the markdown text when the user copy & paste the message which contains code snippet using selection & keyboard shortcut.

    What is the root cause of that problem?

    ```
    code
    ```
    text
    

    If we add above message and copy it using clipboard button and keyboard shortcut each other, different html contents are saved in clipboard.

    <pre>code<br></pre>text \\ copied by clipboard button in context menu
    
    <div><div><comment><pre><div><span>code</span><br></div></pre>text</comment></div></div> \\ copied by selection & Ctrl + C
    

    handlePastedHTML(html) {
    const parser = new ExpensiMark();
    this.paste(parser.htmlToMarkdown(html));
    }

    If we paste it in the composer, above html texts will be parsed by handlePastedHTML function of ExpensiMark class and parsed text will be shown in the composer.

    https://github.com/Expensify/expensify-common/blob/9940dd127c2d44809c98ee628a8057f08c93bfc9/lib/ExpensiMark.js#L322-L324
    For parsing of code snippet, handlePastedHTML function adds head & tail line breaks.
    And it removes the new line character at the end of <pre> tag if it exists, for preventing addition of new line characters.

    <pre><div><span>code</span><br></div></pre>
    

    But through rendering of HTML content, <div> tag is appended inside <pre> and also <br> tag is inside of <div> tag.
    So the end new line character won't be removed and we will see an extra line in markdown text.

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

    function copySelectionToClipboard() {
    const selection = SelectionScraper.getCurrentSelection();

    We should parse selection in advance, before saving it to clipboard & parsing it using htmlToMarkdown function.
    We should remove the child <div> tag inside <pre> tag and the problem will be fixed.

    function parseSelectionHtml(html) {
        return html.replace(/<pre><div>(.*?)<\/div><\/pre>/g, (match, g1) => `<pre>${g1}</pre>`);
    }
    

    We might update this parser function for further updates related to selection, or we can add it to ExpensiMark class.

    What alternative solutions did you explore? (Optional)

    We can add new rule to htmlToMarkdownRules of ExpensifyMark.js directly.
    So we can remove the nested tag inside <pre> tag while html selection is being parsed using htmlToMarkdown function.

    {
        name: 'nested',
        regex: /<(pre)(?:"[^"]*"|'[^']*'|[^'">])*><(div|code)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\2><\/pre>/gi,
        replacement: '<pre>$3</pre>'
    },
    
  11. puneetlath commented on Jul 28, 2023

    @puneetlath
    Contributor

    @mollfpr please review when you get a chance, thanks!

  12. 25 remaining items

  13. melvin-bot commented on Aug 8, 2023

    @melvin-bot

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

    Offer link
    Upwork job

  14. melvin-bot commented on Aug 8, 2023

    @melvin-bot

    📣 @akamefi202 You have been assigned to this job!
    Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
    Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
    Keep in mind: Code of Conduct | Contributing 📖

  15. melvin-bot commented on Aug 8, 2023

    @melvin-bot

    📣 @huzaifa-99 🎉 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

  16. akamefi202 commented on Aug 8, 2023

    @akamefi202
    Contributor

    I applied to the Upwork job and I believe that the PR will be ready by tomorrow.

  17. akamefi202 commented on Aug 9, 2023

    @akamefi202
    Contributor

    I updated proposal.
    I added the discussed solution as alternative solution.

  18. akamefi202 commented on Aug 9, 2023

    @akamefi202
    Contributor
  19. melvin-bot commented on Aug 9, 2023

    @melvin-bot

    @puneetlath @mollfpr @akamefi202 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

  20. added
    Reviewing
    on Aug 9, 2023
  21. added
    Weekly
    and removed
    Daily
    on Aug 14, 2023
  22. melvin-bot commented on Aug 17, 2023

    @melvin-bot

    Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

    • when @akamefi202 got assigned: 2023-08-08 16:29:40 Z
    • when the PR got merged: 2023-08-17 18:48:00 UTC
    • days elapsed: 7

    On to the next one 🚀

  23. changed the title [-][$1000] Web - Markdown pasted from selection-copy is different from clipboard-copy[/-] [+][HOLD for payment 2023-08-30] [$1000] Web - Markdown pasted from selection-copy is different from clipboard-copy[/+] on Aug 27, 2023
  24. akamefi202 commented on Aug 30, 2023

    @akamefi202
    Contributor

    @puneetlath @mollfpr It's Aug 30th. Could you please help me with payment? And can we close this issue now?

  25. puneetlath commented on Aug 30, 2023

    @puneetlath
    Contributor

    All paid. Thanks everyone!

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

Metadata

Metadata

Labels

BugExternalReviewingWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions