-
-
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.
WIP consolidate isExternal and add tests for DOMPurify and isExternal
- Loading branch information
Showing
17 changed files
with
191 additions
and
89 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>docsify</title> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" | ||
/> | ||
<link rel="stylesheet" href="/themes/vue.css" title="vue" /> | ||
</head> | ||
<body> | ||
<!--inject-app--> | ||
<!--inject-config--> | ||
<script src="/lib/docsify.js"></script> | ||
</body> | ||
</html> |
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,8 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const tmplPath = path.resolve(__dirname, 'default-template.html'); | ||
|
||
export function getDefaultTemplate() { | ||
return fs.readFileSync(tmplPath).toString(); | ||
} |
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,14 @@ | ||
// Borrowed from https://j11y.io/snippets/getting-a-fully-qualified-url. | ||
export function qualifyURL(url) { | ||
const img = document.createElement('img'); | ||
img.src = url; // set string url | ||
url = img.src; // get qualified url | ||
img.src = ''; // prevent the server request | ||
return url; | ||
} | ||
|
||
export function isExternal(url) { | ||
url = qualifyURL(url); | ||
url = new URL(url); | ||
return url.origin !== location.origin; | ||
} |
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,24 @@ | ||
/* eslint-disable no-global-assign */ | ||
require = require('esm')(module /* , options */); | ||
const { expect } = require('chai'); | ||
const { initJSDOM } = require('../../../test/_helper'); | ||
const { isExternal } = require('./utils'); | ||
|
||
describe('isExternal', () => { | ||
it('detects external whether links are external', async () => { | ||
initJSDOM('', { | ||
url: 'http://127.0.0.1:3000', | ||
runScripts: 'dangerously', | ||
resources: 'usable', | ||
}); | ||
|
||
expect(isExternal).to.be.instanceOf(Function); | ||
expect(isExternal('/foo.md')).to.be.false; | ||
expect(isExternal('//foo.md')).to.be.true; | ||
expect(isExternal('//127.0.0.1:3000/foo.md')).to.be.false; | ||
expect(isExternal('http://127.0.0.1:3001/foo.md')).to.be.true; | ||
expect(isExternal('https://google.com/foo.md')).to.be.true; | ||
expect(isExternal('//google.com/foo.md')).to.be.true; | ||
expect(isExternal('/google.com/foo.md')).to.be.false; | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.