mirror of
https://github.com/docsifyjs/docsify.git
synced 2026-10-17 04:31:18 +08:00
test(unit): add test cases on isExternal. (#1515)
* test(unit): add test cases on xss.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
const { isExternal } = require('../../src/core/util');
|
||||
|
||||
// Core util
|
||||
// -----------------------------------------------------------------------------
|
||||
describe('core/util', () => {
|
||||
// isExternal()
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('isExternal()', () => {
|
||||
// cases non external
|
||||
test('non external local url with one /', () => {
|
||||
const result = isExternal(`/${location.host}/docsify/demo.md`);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('non external local url with two //', () => {
|
||||
const result = isExternal(`//${location.host}/docsify/demo.md`);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('non external local url with three ///', () => {
|
||||
const result = isExternal(`///${location.host}/docsify/demo.md`);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('non external local url with more /', () => {
|
||||
const result = isExternal(
|
||||
`//////////////////${location.host}/docsify/demo.md`
|
||||
);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('non external url with one /', () => {
|
||||
const result = isExternal('/example.github.io/docsify/demo.md');
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
// cases is external
|
||||
test('external url with two //', () => {
|
||||
const result = isExternal('/docsify/demo.md');
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('external url with three ///', () => {
|
||||
const result = isExternal('///example.github.io/docsify/demo.md');
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
test('external url with more /', () => {
|
||||
const result = isExternal(
|
||||
'//////////////////example.github.io/docsify/demo.md'
|
||||
);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user