Skip to content

Commit

Permalink
adds tests for isValid url validation method
Browse files Browse the repository at this point in the history
  • Loading branch information
mattoberle committed Apr 9, 2021
1 parent c2452a8 commit a1bef19
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/quill/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ SafeLink.tagName = 'A';


export { SafeLink as default };
export { isValid };
49 changes: 49 additions & 0 deletions lib/quill/link.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { isValid } from './link';

describe('SafeLink', () => {
describe('isValid', () => {
test('allows anchor links', () => {
expect(isValid('#anchor-link')).toEqual(true);
});

test('allows links relative to the site root', () => {
expect(isValid('/section')).toEqual(true);
});

test('allows mailto links', () => {
expect(isValid('mailto:[email protected]')).toEqual(true);
});

test('allows ftp links', () => {
expect(isValid('ftp://example.com/file')).toEqual(true);
});

test('allows http links', () => {
expect(isValid('http://example.com/foo')).toEqual(true);
});

test('allows https links', () => {
expect(isValid('https://example.com/foo')).toEqual(true);
});

test('allows links without path', () => {
expect(isValid('https://example.com')).toEqual(true);
});

test('rejects anchor links with spaces', () => {
expect(isValid('#anchor link')).toEqual(false);
});

test('rejects links relative to current page', () => {
expect(isValid('section')).toEqual(false);
});

test('rejects mailto links without @', () => {
expect(isValid('mailto:example')).toEqual(false);
});

test('rejects links without a protocol', () => {
expect(isValid('example.com/foo')).toEqual(false);
});
});
});

0 comments on commit a1bef19

Please sign in to comment.