2021-04-11 20:48:31 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
describe('markdown formatted links to', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.visitTestEditor()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('external domains render as external link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[external](https://hedgedoc.org/)')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('have.attr', 'href', 'https://hedgedoc.org/')
|
|
|
|
.should('have.attr', 'rel', 'noreferer noopener')
|
|
|
|
.should('have.attr', 'target', '_blank')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('note anchor references render as anchor link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[anchor](#anchor)')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('have.attr', 'href', 'http://127.0.0.1:3001/n/test#anchor')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('internal pages render as internal link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[internal](other-note)')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('have.attr', 'href', 'http://127.0.0.1:3001/n/other-note')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('data URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[data](data:text/plain,evil)')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('not.exist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('javascript URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[js](javascript:alert("evil"))')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('not.exist')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('HTML anchor element links to', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.visitTestEditor()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('external domains render as external link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="https://hedgedoc.org/">external</a>')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('have.attr', 'href', 'https://hedgedoc.org/')
|
|
|
|
.should('have.attr', 'rel', 'noreferer noopener')
|
|
|
|
.should('have.attr', 'target', '_blank')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('note anchor references render as anchor link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="#anchor">anchor</a>')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('have.attr', 'href', 'http://127.0.0.1:3001/n/test#anchor')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('internal pages render as internal link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="other-note">internal</a>')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('have.attr', 'href', 'http://127.0.0.1:3001/n/other-note')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('data URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="data:text/plain,evil">data</a>')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('not.exist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('javascript URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="javascript:alert(\'evil\')">js</a>')
|
2021-04-11 20:48:31 +00:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('a')
|
|
|
|
.should('not.exist')
|
|
|
|
})
|
|
|
|
})
|