-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(unit): add test cases on isExternal. (#1515)
* test(unit): add test cases on xss.
- Loading branch information
Showing
3 changed files
with
96 additions
and
27 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
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 |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); |
abda30d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: