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

Use the href of links for link previews, not node.textContent #3873

Merged
merged 2 commits into from
Mar 3, 2023

Conversation

mejo-
Copy link
Member

@mejo- mejo- commented Mar 2, 2023

Until now we used node.textContent to determine whether a paragraph is a link that warrants a link preview. Instead, we now check whether the paragraph has a single text node wich is a link and use its href.

Text nodes with empty textContent are ignored in order to allow whitespaces before and after the link.

This way we ensure to always show the preview of the link target, not of the description text. Both may differ, which has security implications.

Also, links with a custom description get a link preview as well.

And last but not least, it fixes link previes for URLs with spaces. (Background: for some reason, url-encoded spaces in textContent of links get decoded when they're transformed to markdown and written to a file. Therefore URLs with spaces lost their link preview once the Text session was closed prior to this commit)

Fixes: #3871

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation (README or documentation) has been updated or is not required

@mejo- mejo- added bug Something isn't working 3. to review labels Mar 2, 2023
@mejo- mejo- added this to the Nextcloud 26 milestone Mar 2, 2023
@cypress
Copy link

cypress bot commented Mar 2, 2023

2 flaky tests on run #8849 ↗︎

0 139 0 0 Flakiness 2

Details:

Use the href of links for link previews, not `node.textContent`
Project: Text Commit: 343b6542e3
Status: Passed Duration: 03:26 💡
Started: Mar 3, 2023 8:59 PM Ended: Mar 3, 2023 9:03 PM
Flakiness  sync.spec.js • 1 flaky test

View Output Video

Test Artifacts
Sync > recovers from a lost connection Output Screenshots
Flakiness  share.spec.js • 1 flaky test

View Output Video

Test Artifacts
Open test.md in viewer > Share a file with download disabled shows an error Output Screenshots

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the quick fixing :)

@juliusknorr
Copy link
Member

/backport to stable26

@juliusknorr
Copy link
Member

/backport to stable25

@mejo- mejo- force-pushed the fix/reference_use_link_href branch from dcc44fd to 2fc65e7 Compare March 3, 2023 15:36
@mejo-
Copy link
Member Author

mejo- commented Mar 3, 2023

/compile

Until now we used node.textContent to determine whether a paragraph is
a link that warrants a link preview. Instead, we now check whether the
paragraph has a single text node wich is a link and use its href.

Text nodes with empty textContent are ignored in order to allow
whitespaces before and after the link.

This way we ensure to always show the preview of the link target, not of
the description text. Both may differ, which has security implications.

Also, links with a custom description get a link preview as well.

And last but not least, it fixes link previes for URLs with spaces.
(Background: for some reason, url-encoded spaces in textContent of links
get decoded when they're transformed to markdown and written to a file.
Therefore URLs with spaces lost their link preview once the Text session
was closed prior to this commit)

Fixes: #3871

Signed-off-by: Jonas <[email protected]>
@mejo- mejo- force-pushed the fix/reference_use_link_href branch from 38e15e2 to 35db3d4 Compare March 3, 2023 20:20
@mejo-
Copy link
Member Author

mejo- commented Mar 3, 2023

/compile

Signed-off-by: nextcloud-command <[email protected]>
@mejo- mejo- merged commit a451b5b into main Mar 3, 2023
@delete-merged-branch delete-merged-branch bot deleted the fix/reference_use_link_href branch March 3, 2023 21:05
@backportbot-nextcloud
Copy link

The backport to stable25 failed. Please do this backport manually.

@mejo-
Copy link
Member Author

mejo- commented Mar 3, 2023

/backport 35db3d4 to stable25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use href of links instead of node.textContent for link previews
3 participants