From 16b5ba5e707e2108818a369ea729b6691941a822 Mon Sep 17 00:00:00 2001 From: aluc Date: Wed, 3 Nov 2021 21:41:21 +0900 Subject: [PATCH] fix: files from basePath should be remoteUrl:false --- src/core/fetch/index.js | 5 +++-- src/core/util/core.js | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index f0f288798..9ebe593d3 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -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 { @@ -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); diff --git a/src/core/util/core.js b/src/core/util/core.js index 50b7ed02c..e95d875ba 100644 --- a/src/core/util/core.js +++ b/src/core/util/core.js @@ -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' &&