fix: relative bug.

This commit is contained in:
Rintim 2024-05-07 00:02:32 +08:00
parent 901d01fe36
commit 3016b46439
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
1 changed files with 4 additions and 0 deletions

View File

@ -4804,6 +4804,10 @@ export class Get {
*/ */
relativePath(url, addAssetURL = false) { relativePath(url, addAssetURL = false) {
let base = lib.path.relative(decodeURI(rootURL.pathname), decodeURI(url.pathname)).slice(3); let base = lib.path.relative(decodeURI(rootURL.pathname), decodeURI(url.pathname)).slice(3);
// 由于`rootURL`的实现当且仅当url指向`~/noname.js`时,会变为空字符串
if (base == "") {
base = "noname.js";
}
if (addAssetURL && rootURL.protocol == "file:") { if (addAssetURL && rootURL.protocol == "file:") {
base = `${lib.assetURL}${base}`; base = `${lib.assetURL}${base}`;
} }