-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
is_external_link.spec.js
48 lines (40 loc) · 1.48 KB
/
is_external_link.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
describe('isExternalLink', () => {
const ctx = {
config: {
url: 'https://example.com',
external_link: {}
}
};
const isExternalLink = require('../lib/is_external_link').bind(ctx);
it('external link', () => {
isExternalLink('https://hexo.io/').should.eql(true);
});
it('internal link', () => {
isExternalLink('https://example.com').should.eql(false);
isExternalLink('//example.com').should.eql(false);
isExternalLink('//example.com/archives/foo.html').should.eql(false);
isExternalLink('/archives/foo.html').should.eql(false);
});
it('hash, mailto, javascript', () => {
isExternalLink('#top').should.eql(false);
isExternalLink('mailto:hi@hexo.io').should.eql(false);
isExternalLink('javascript:alert(\'Hexo is Awesome\')').should.eql(false);
});
it('exclude - empty string', () => {
ctx.config.external_link.exclude = '';
isExternalLink('https://hexo.io/').should.eql(true);
});
it('exclude - string', () => {
ctx.config.external_link.exclude = 'foo.com';
isExternalLink('https://foo.com/').should.eql(false);
isExternalLink('https://bar.com/').should.eql(true);
isExternalLink('https://baz.com/').should.eql(true);
});
it('exclude - array', () => {
ctx.config.external_link.exclude = ['foo.com', 'bar.com'];
isExternalLink('https://foo.com/').should.eql(false);
isExternalLink('https://bar.com/').should.eql(false);
isExternalLink('https://baz.com/').should.eql(true);
});
});