Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(links): only preview and link known protocols
Only generate previews for http and https.
Only link to http, https, mailto, and tel.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Oct 2, 2024
commit 2bbff4147fc9371052f4c47f1c33549b118cc471
24 changes: 24 additions & 0 deletions cypress/e2e/nodes/Links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ describe('test link marks', function() {
.should('have.been.calledWith', link)
})

it('Handles typed in markdown links with text', () => {
const link = 'https://nextcloud.com/'
cy.insertLine(`[text](${link})`)
clickLink(link)
cy.get('.link-view-bubble .widget-default', { timeout: 10000 })
.find('.widget-default--name')
.contains('Nextcloud')
cy.get('.link-view-bubble a')
.should('have.attr', 'href', link)
})

it('Leaves out link to other protocols', () => {
const link = 'other://protocol'
cy.insertLine(`[text](${link})`)
cy.getContent()
.find(`a[href*="${link}"]`)
.should('not.exist')
clickLink('#')
cy.get('.link-view-bubble__title', { timeout: 10000 })
.contains('other://protocol')
cy.get('.link-view-bubble a')
.should('not.exist')
})

})

describe('autolink', function() {
Expand Down
9 changes: 8 additions & 1 deletion src/components/Link/LinkBubbleView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</div>

<!-- link preview -->
<NcReferenceList v-else-if="href"
<NcReferenceList v-else-if="showPreview"
ref="referencelist"
:text="sanitizedHref"
:limit="1"
Expand All @@ -97,6 +97,8 @@ import PencilIcon from 'vue-material-design-icons/Pencil.vue'

import CopyToClipboardMixin from '../../mixins/CopyToClipboardMixin.js'

const PROTOCOLS_WITH_PREVIEW = ['http:', 'https:']

export default {
name: 'LinkBubbleView',

Expand Down Expand Up @@ -162,6 +164,11 @@ export default {
title() {
return this.referenceTitle ? this.referenceTitle : this.sanitizedHref
},

showPreview() {
const url = new URL(this.href, window.location)
return this.href && PROTOCOLS_WITH_PREVIEW.includes(url.protocol)
},
},

watch: {
Expand Down