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 <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Oct 1, 2024
1 parent 37d0b79 commit bc88c57
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 @@ -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

0 comments on commit bc88c57

Please sign in to comment.