2021-04-11 20:48:31 +00:00
|
|
|
/*
|
2022-06-08 11:19:51 +00:00
|
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
2021-04-11 20:48:31 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
describe('markdown formatted links to', () => {
|
|
|
|
beforeEach(() => {
|
2022-01-30 20:46:43 +00:00
|
|
|
cy.visitTestNote()
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/test#anchor')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('internal pages render as internal link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[internal](other-note)')
|
2021-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/other-note')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('data URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[data](data:text/plain,evil)')
|
2021-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('not.exist')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('javascript URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('[js](javascript:alert("evil"))')
|
2021-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('not.exist')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('HTML anchor element links to', () => {
|
|
|
|
beforeEach(() => {
|
2022-01-30 20:46:43 +00:00
|
|
|
cy.visitTestNote()
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/test#anchor')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('internal pages render as internal link', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="other-note">internal</a>')
|
2021-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/other-note')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('not.have.attr', 'href')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('javascript URIs do not render', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('<a href="javascript:alert(\'evil\')">js</a>')
|
2021-11-02 07:15:33 +00:00
|
|
|
cy.getMarkdownBody().find('a').should('not.have.attr', 'href')
|
2021-04-11 20:48:31 +00:00
|
|
|
})
|
|
|
|
})
|