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