Skip to content

Commit

Permalink
fix: files from basePath should be remoteUrl:false
Browse files Browse the repository at this point in the history
  • Loading branch information
b6pzeusbc54tvhw5jgpyw8pwz2x6gs committed Nov 3, 2021
1 parent c3cdadc commit 16b5ba5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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

0 comments on commit 16b5ba5

Please sign in to comment.