Skip to content

Commit

Permalink
fix: do not follow data URIs (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Nov 3, 2019
1 parent e55edb1 commit f8eefcb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class LinkChecker extends EventEmitter {
*/
async check(options: CheckOptions) {
options.linksToSkip = options.linksToSkip || [];
options.linksToSkip.push('^mailto:', '^irc:');
options.linksToSkip.push('^mailto:', '^irc:', '^data:');
let server: http.Server | undefined;
if (!options.path.startsWith('http')) {
const port = options.port || 5000 + Math.round(Math.random() * 1000);
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/mailto/index.html

This file was deleted.

2 changes: 2 additions & 0 deletions test/fixtures/protocols/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<html>
<body>
<a href="irc://irc.freenode.net/%23bootstrap">visit us on irc</a>
<a href="mailto:email@example.com">send me an email</a>
<img src="data:text/plain;charset=utf-8;base64,8J+Qvw==">
</body>
</html>
12 changes: 2 additions & 10 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ describe('linkinator', () => {
requestStub.restore();
});

it('should skip mailto: links', async () => {
const results = await check({ path: 'test/fixtures/mailto' });
assert.ok(results.passed);
assert.strictEqual(
results.links.filter(x => x.state === LinkState.SKIPPED).length,
1
);
});

it('should report malformed links as broken', async () => {
const results = await check({ path: 'test/fixtures/malformed' });
assert.ok(!results.passed);
Expand Down Expand Up @@ -131,11 +122,12 @@ describe('linkinator', () => {
});

it('should not folow non-http[s] links', async () => {
// includes mailto, data urls, and irc
const results = await check({ path: 'test/fixtures/protocols' });
assert.ok(results.passed);
assert.strictEqual(
results.links.filter(x => x.state === LinkState.SKIPPED).length,
1
3
);
});

Expand Down

0 comments on commit f8eefcb

Please sign in to comment.