Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export function fetchMixin(proto) {
};

proto._fetch = function(cb = noop) {
const { basePath } = this.config;
const { query } = this.route;
let { path } = this.route;

// Prevent loading remote content via URL hash
// Ex: https://foo.com/#//bar.com/file.md
if (isExternal(path)) {
if (isExternal(path, basePath)) {
history.replaceState(null, '', '#');
this.router.normalize();
} else {
Expand All @@ -92,7 +93,7 @@ export function fetchMixin(proto) {
const file = this.router.getFile(path);
const req = request(file + qs, true, requestHeaders);

this.isRemoteUrl = isExternal(file);
this.isRemoteUrl = isExternal(file, basePath);
// Current page is html
this.isHTML = /\.html$/g.test(file);

Expand Down
18 changes: 14 additions & 4 deletions src/core/util/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,20 @@ export function isFn(obj) {
* @param {String} string url
* @returns {Boolean} True if the passed-in url is external
*/
export function isExternal(url) {
let match = url.match(
/^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
);
export function isExternal(url, basePath) {
const regExp = /^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/;
let match = url.match(regExp);

if (basePath) {
const matchWithBasePath = basePath.match(regExp);
if (
match && matchWithBasePath &&
match[1] === matchWithBasePath[1] &&
match[2] === matchWithBasePath[2]
) {
return false;
}
}

if (
typeof match[1] === 'string' &&
Expand Down