Skip to content

Commit

Permalink
Fix reource load issue in local downloaded npm package (#2436)
Browse files Browse the repository at this point in the history
* fix(shader-lab):  resource load issue in local downloaded NPM package
  • Loading branch information
Sway007 authored Nov 15, 2024
1 parent 7da32a5 commit 4ef480e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 3 additions & 5 deletions packages/core/src/asset/ResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export class ResourceManager {
let assetBaseURL = baseUrl;
if (searchStr) {
const params = searchStr.split("&");
for (let i = 0; i < params.length; i++) {
for (let i = params.length - 1; i >= 0; i--) {
const param = params[i];
if (param.startsWith(`q=`)) {
queryPath = decodeURIComponent(param.split("=")[1]);
Expand Down Expand Up @@ -573,11 +573,9 @@ export class ResourceManager {
Logger.warn(`refId:${refId} is not find in this._editorResourceConfig.`);
return Promise.resolve(null);
}
const remoteUrl = resourceConfig.path;
const queryPath = new URL(remoteUrl).search;
let url = resourceConfig.virtualPath + queryPath;
let url = resourceConfig.virtualPath;
if (key) {
url += (url.indexOf("?") > -1 ? "&" : "?") + "q=" + key;
url += "?q=" + key;
}

promise = this.load<any>({
Expand Down
15 changes: 14 additions & 1 deletion tests/src/core/resource/ResourceManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssetPromise, ResourceManager, Texture2D } from "@galacean/engine-core";
import { AssetPromise, AssetType, ResourceManager, Texture2D } from "@galacean/engine-core";
import { WebGLEngine } from "@galacean/engine-rhi-webgl";
import chai, { expect } from "chai";
import spies from "chai-spies";
Expand Down Expand Up @@ -81,4 +81,17 @@ describe("ResourceManager", () => {
chai.spy.restore(glTFLoader, "load");
});
});

describe("gltf subAsset load", () => {
it("invalid q case", async () => {
const loadRes = await engine.resourceManager.load({
// contains invalid q value cdn url.
url: "https://mdn.alipayobjects.com/huamei_aftkdx/afts/file/A*_Ao1QZtL9fMAAAAAAAAAAAAADteEAQ/mock-project.json",
type: AssetType.Project
});
expect(loadRes).to.equal(undefined);
});

// TODO: case for gltf loader load invalid q url, expect to throw
});
});

0 comments on commit 4ef480e

Please sign in to comment.