Skip to content

Commit

Permalink
Use the href of links for link previews, not node.textContent
Browse files Browse the repository at this point in the history
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 <jonas@freesources.org>
  • Loading branch information
mejo- authored and backportbot-nextcloud[bot] committed Mar 3, 2023
1 parent 1b4061a commit bff106b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nodes/ParagraphView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export default {
},
beforeCreate() {
this.debouncedUpdateText = debounce((newNode) => {
this.text = this.getTextReference(this.node?.textContent)
this.text = this.getTextReference(this.node)
}, 500)
},
created() {
this.text = this.getTextReference(this.node?.textContent)
this.text = this.getTextReference(this.node)
},
beforeUnmount() {
this.debouncedUpdateText?.cancel()
Expand Down

0 comments on commit bff106b

Please sign in to comment.