mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:10:55 +00:00
54604c4313
## Description:
buildAssetUrl had a middle branch that, when called with a directory-ish
path (e.g. assetUrl("maps")), would check whether any manifest entry had
that prefix and return an unhashed /_assets/<path> URL. This was wrong:
* The /_assets/ prefix implies a managed, hashed asset — but the
returned URL is neither. It won't exist on R2 after the migration.
* It defeats cache-busting, since no hash is applied.
* It encourages callers to reconstruct asset paths by hand via string
concatenation, bypassing the manifest as the single source of truth.
Renaming or reorganizing an asset directory would silently break callers
the manifest can't help locate.
## Please complete the following:
- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
## Please put your Discord username so you can be contacted if a bug or
regression is found:
evan
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { buildAssetUrl } from "../src/core/AssetUrls";
|
|
|
|
describe("AssetUrls", () => {
|
|
test("returns hashed URLs for direct asset matches", () => {
|
|
expect(
|
|
buildAssetUrl("images/Favicon.svg", {
|
|
"images/Favicon.svg": "/_assets/images/Favicon.hash.svg",
|
|
}),
|
|
).toBe("/_assets/images/Favicon.hash.svg");
|
|
});
|
|
|
|
test("falls back to the unversioned path when manifest has no match", () => {
|
|
expect(buildAssetUrl("images/unknown.svg", {})).toBe("/images/unknown.svg");
|
|
});
|
|
|
|
test("falls back to the unversioned path for directory-like paths", () => {
|
|
const manifest = {
|
|
"maps/britanniaclassic/manifest.json":
|
|
"/_assets/maps/britanniaclassic/manifest.hash.json",
|
|
"maps/britanniaclassic/map.bin":
|
|
"/_assets/maps/britanniaclassic/map.hash.bin",
|
|
};
|
|
|
|
expect(buildAssetUrl("maps", manifest)).toBe("/maps");
|
|
expect(buildAssetUrl("maps/britanniaclassic", manifest)).toBe(
|
|
"/maps/britanniaclassic",
|
|
);
|
|
});
|
|
|
|
test("rejects dot segments in asset paths", () => {
|
|
expect(() => buildAssetUrl("../api/instance", {})).toThrow(
|
|
"Invalid asset path segment: ..",
|
|
);
|
|
expect(() => buildAssetUrl("images/%2e%2e/secret.svg", {})).toThrow(
|
|
"Invalid asset path segment: %2e%2e",
|
|
);
|
|
});
|
|
|
|
test("rejects empty asset paths", () => {
|
|
expect(() => buildAssetUrl("", {})).toThrow("Asset path must not be empty");
|
|
expect(() => buildAssetUrl("///", {})).toThrow(
|
|
"Asset path must not be empty",
|
|
);
|
|
});
|
|
});
|