-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: adjust validate and add shouldAutoLink to improve URL handling
- Loading branch information
Showing
5 changed files
with
122 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@tiptap/extension-link": patch | ||
"tiptap-demos": patch | ||
--- | ||
|
||
Refactor validate and add shouldAutoLink function to improve URL handling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,27 +12,27 @@ context('/src/Marks/Link/React/', () => { | |
|
||
it('should parse a tags correctly', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.commands.setContent('<p><a href="#">Example Text1</a></p>') | ||
editor.commands.setContent('<p><a href="https://example.com">Example Text1</a></p>') | ||
expect(editor.getHTML()).to.eq( | ||
'<p><a target="_blank" rel="noopener noreferrer nofollow" href="#">Example Text1</a></p>', | ||
'<p><a target="_blank" rel="noopener noreferrer nofollow" href="https://example.com">Example Text1</a></p>', | ||
) | ||
}) | ||
}) | ||
|
||
it('should parse a tags with target attribute correctly', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.commands.setContent('<p><a href="#" target="_self">Example Text2</a></p>') | ||
editor.commands.setContent('<p><a href="https://example.com" target="_self">Example Text2</a></p>') | ||
expect(editor.getHTML()).to.eq( | ||
'<p><a target="_self" rel="noopener noreferrer nofollow" href="#">Example Text2</a></p>', | ||
'<p><a target="_self" rel="noopener noreferrer nofollow" href="https://example.com">Example Text2</a></p>', | ||
) | ||
}) | ||
}) | ||
|
||
it('should parse a tags with rel attribute correctly', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.commands.setContent('<p><a href="#" rel="follow">Example Text3</a></p>') | ||
editor.commands.setContent('<p><a href="https://example.com" rel="follow">Example Text3</a></p>') | ||
expect(editor.getHTML()).to.eq( | ||
'<p><a target="_blank" rel="follow" href="#">Example Text3</a></p>', | ||
'<p><a target="_blank" rel="follow" href="https://example.com">Example Text3</a></p>', | ||
) | ||
}) | ||
}) | ||
|
@@ -54,7 +54,7 @@ context('/src/Marks/Link/React/', () => { | |
|
||
it('should allow exiting the link once set', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.commands.setContent('<p><a href="#" target="_self">Example Text2</a></p>') | ||
editor.commands.setContent('<p><a href="https://example.com" target="_self">Example Text2</a></p>') | ||
cy.get('.tiptap').type('{rightArrow}') | ||
|
||
cy.get('button:first').should('not.have.class', 'is-active') | ||
|
@@ -129,4 +129,32 @@ context('/src/Marks/Link/React/', () => { | |
.find('a[href="http://example3.com/foobar"]') | ||
.should('contain', 'http://example3.com/foobar') | ||
}) | ||
|
||
it('should not allow links with disallowed protocols', () => { | ||
const disallowedProtocols = ['ftp://example.com', 'file:///example.txt', 'mailto:[email protected]'] | ||
|
||
disallowedProtocols.forEach(url => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.commands.setContent(`<p><a href="${url}">Example Text</a></p>`) | ||
expect(editor.getHTML()).to.not.include(`<a href="${url}">`) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not allow links with disallowed domains', () => { | ||
const disallowedDomains = ['https://example-phishing.com', 'https://malicious-site.net'] | ||
|
||
disallowedDomains.forEach(url => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.commands.setContent(`<p><a href="${url}">Example Text</a></p>`) | ||
expect(editor.getHTML()).to.not.include(`<a href="${url}">`) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not auto-link a URL from a disallowed domain', () => { | ||
cy.get('.tiptap').type('https://example-phishing.com ') // disallowed domain | ||
cy.get('.tiptap').should('not.have.descendants', 'a') | ||
cy.get('.tiptap').should('contain.text', 'https://example-phishing.com') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters