[HOLD for payment 2021-09-16] Desktop - Big empty space in message fields if copy/paste the Text from MAC Note.app
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:
- Navigate to a conversation that has some messages.
- 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

Expensify/Expensify Issue URL:
: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:
- Identify the pull request that introduced this issue and revert it.
- Find someone who can quickly fix the issue.
- Fix the issue yourself.
Triggered auto assignment to @bondydaa (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
I am OOO
@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?
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.
I think we should demote this from deploy blocker to regular-old 🐛
This hasn't been looked at in 9 days and has no assignee. Bumping to daily and making it External so we do something.
Triggered auto assignment to @kadiealexander (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
@parasharrajat is this related at all to https://github.com/Expensify/App/issues/4759?
@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.
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
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
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.
Mine was on desktop app too, just FYI for the thread.
Thanks for helping me troubleshoot it @parasharrajat! Will post to UW now :)
I have found the fix as well. Preparing the proposal now.
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
-
We should only parse the body tag, if present as only the body tag contains a representational text.
-
we only use content present between
bodytag ifbodytag is present. Then apply all of our parsing rules. -
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.
Upwork job: https://www.upwork.com/jobs/~01078e92ead30d76a6
Triggered auto assignment to @johnmlee101 (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@johnmlee101 when you get a moment, would you mind reviewing the existing proposals here?
Love the proposal @parasharrajat .
@kadiealexander feel free to assign out the job!