App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2021-09-16] Desktop - Big empty space in message fields if copy/paste the Text from MAC Note.app

Open kavimuru opened this issue 5 years ago • 28 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Issue was found when executing the PR #4363

Action Performed:

  1. Navigate to a conversation that has some messages.
  2. Paste the Text from MAC note.app to the composer.

Expected Result:

Only entered message should be visible in compose field if copy/paste the Text from MAC Note.app

Actual Result:

Big empty space in message compose field if copy/past the Text from MAC Note.app

Workaround:

Unknown

Platform:

Where is this issue occurring?

  • Desktop App

Version Number: v1.0.83-0 Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos:

https://user-images.githubusercontent.com/43996225/128581157-fbeefcae-5559-4e17-b406-ed462d15c44c.mp4

Bug5182815_empty

Expensify/Expensify Issue URL:

View all open jobs on Upwork

kavimuru avatar Aug 07 '21 00:08 kavimuru

:wave: Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open StagingDeployCash deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

OSBotify avatar Aug 07 '21 00:08 OSBotify

Triggered auto assignment to @bondydaa (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Aug 07 '21 00:08 MelvinBot

I am OOO

bondydaa avatar Aug 07 '21 22:08 bondydaa

@parasharrajat - just checking, it looks like you were aware of this issue, correct? Was there a separate GH issue that was opened to track the bug where newlines are prepended to messages pasted into the message box?

francoisl avatar Aug 10 '21 20:08 francoisl

No, a new issue was not opened at that time. I was waiting for #4363 to merge as only after that, this behaviour is revealed. So with an inspection, I come to know that the Mac Note app. usages   chars to show spaces which are also needed to be escaped and current _.unescape does not do that. I think we need a custom implementation as is not made to parse HTMLEntities and its usages do not seem sufficient any more.

About the main issue, let me quickly take a good peek at it. Only then I can tell what is causing this much space.

parasharrajat avatar Aug 10 '21 20:08 parasharrajat

I think we should demote this from deploy blocker to regular-old 🐛

roryabraham avatar Aug 11 '21 00:08 roryabraham

This hasn't been looked at in 9 days and has no assignee. Bumping to daily and making it External so we do something.

marcaaron avatar Aug 21 '21 01:08 marcaaron

Triggered auto assignment to @kadiealexander (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Aug 21 '21 01:08 MelvinBot

@parasharrajat is this related at all to https://github.com/Expensify/App/issues/4759?

kadiealexander avatar Aug 22 '21 22:08 kadiealexander

@kadiealexander https://github.com/Expensify/App/issues/4759 is needed to improve the parsing. But I was not able to reproduce the same behavior of this issue. There is space between pasted text but not before or after.

parasharrajat avatar Aug 22 '21 22:08 parasharrajat

After fixing https://github.com/Expensify/App/issues/4759, I get this where I see no space.

https://user-images.githubusercontent.com/24370807/130372692-796af653-411b-43ac-b749-6c55c75678dc.mp4

parasharrajat avatar Aug 22 '21 23:08 parasharrajat

What version are you working with @parasharrajat? I just tested on version 1.0.85-9 (1.0.85-9) and I still see the white space above the message:

https://user-images.githubusercontent.com/59587260/130373230-a3d23ffe-d83f-41ea-86d5-4336f58c38a3.mp4

kadiealexander avatar Aug 22 '21 23:08 kadiealexander

Ok. I think it's specific to chrome. Let me retest.

@kadiealexander ~I am on v1.0.86-4 and for me, chrome is also fine.~

EDIT: it may be note.app version. My Note.app version is 4.7

Sorry I got it now. It is reproducible now.

parasharrajat avatar Aug 22 '21 23:08 parasharrajat

Mine was on desktop app too, just FYI for the thread.

Thanks for helping me troubleshoot it @parasharrajat! Will post to UW now :)

kadiealexander avatar Aug 22 '21 23:08 kadiealexander

I have found the fix as well. Preparing the proposal now.

parasharrajat avatar Aug 22 '21 23:08 parasharrajat

Explanation

We faced an issue before where there were extra spaces on the Windows platform as windows surround the pasted HTML between html & body tags. Similarly, I found, in this case, the Whole valid HTML5 document is copied into the clipboard. It contains whole meta tags, head, doctype, link, and others. But Each tag contains a trailing newline for example

<html>\n
<body>\n
asdasdsadsadsad
</body>\n
</html>\n

While we trim all these extra tags but all those newlines are being prepended which creates a big empty space.

Proposal

  1. We should only parse the body tag, if present as only the body tag contains a representational text.

  2. we only use content present between body tag if body tag is present. Then apply all of our parsing rules.

  3. We don't need this rule

  {
                name: 'Strip Special Tags',
                regex: /(\n|\r\n)?<\/?(html|body)(?:"[^"]*"|'[^']*'|[^'"><])*>(?![^<]*(<\/pre>|<\/code>))(\n|\r\n)?/gim,
                replacement: ''
            },

Instead in htmlToMarkdown method we first try to find the body tag. if found we replace the original text being converted with its content.

 let generatedMarkdown = htmlString;
        const body = /<(body)(?:"[^"]*"|'[^']*'|[^'"><])*>(?:\n|\r\n)?([\s\S]*?)(?:\n|\r\n)?<\/\1>(?![^<]*(<\/pre>|<\/code>))/im;
        const parseBodyTag = generatedMarkdown.match(body);
        if(parseBodyTag){
            generatedMarkdown = parseBodyTag[2];
        }

This will trim the Extra newlines. At last, I suggest we should use a mature html-to-md parser. Otherwise, we will have many bugs like this.

parasharrajat avatar Aug 23 '21 00:08 parasharrajat

Upwork job: https://www.upwork.com/jobs/~01078e92ead30d76a6

kadiealexander avatar Aug 23 '21 00:08 kadiealexander

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

MelvinBot avatar Aug 23 '21 00:08 MelvinBot

@johnmlee101 when you get a moment, would you mind reviewing the existing proposals here?

kadiealexander avatar Aug 25 '21 01:08 kadiealexander

Love the proposal @parasharrajat .

@kadiealexander feel free to assign out the job!

johnmlee101 avatar Aug 25 '21 15:08 johnmlee101