Skip to content

Commit

Permalink
fix(links): only preview and link known protocols
Browse files Browse the repository at this point in the history
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
1 parent a5e5074 commit 4e824ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
24 changes: 24 additions & 0 deletions cypress/e2e/nodes/Links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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 @@ -69,7 +69,7 @@
</div>

<!-- link preview -->
<NcReferenceList v-else-if="href"
<NcReferenceList v-else-if="showPreview"
ref="referencelist"
:text="sanitizedHref"
:limit="1"
Expand All @@ -92,6 +92,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 @@ -157,6 +159,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

0 comments on commit 4e824ca

Please sign in to comment.