mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
fix: normalize admin basepath to prevent double slashes in URLs
Strip trailing slashes from adminBasepath in AdminController window context and wouter Router base to prevent paths like /admin//data when users configure adminBasepath with a trailing slash. Amp-Thread-ID: https://ampcode.com/threads/T-019ca537-4cc4-7174-bf9a-5325d782f097 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -203,6 +203,63 @@ describe("AppReduced", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("withBasePath - double slash fix (admin_basepath with trailing slash)", () => {
|
||||
it("should not produce double slashes when admin_basepath has trailing slash", () => {
|
||||
const options: BkndAdminProps["config"] = {
|
||||
basepath: "/",
|
||||
admin_basepath: "/admin/",
|
||||
logo_return_path: "/",
|
||||
};
|
||||
|
||||
appReduced = new AppReduced(mockAppJson, options);
|
||||
const result = appReduced.withBasePath("/data");
|
||||
|
||||
expect(result).toBe("/admin/data");
|
||||
expect(result).not.toContain("//");
|
||||
});
|
||||
|
||||
it("should work correctly when admin_basepath has no trailing slash", () => {
|
||||
const options: BkndAdminProps["config"] = {
|
||||
basepath: "/",
|
||||
admin_basepath: "/admin",
|
||||
logo_return_path: "/",
|
||||
};
|
||||
|
||||
appReduced = new AppReduced(mockAppJson, options);
|
||||
const result = appReduced.withBasePath("/data");
|
||||
|
||||
expect(result).toBe("/admin/data");
|
||||
});
|
||||
|
||||
it("should handle absolute paths with admin_basepath trailing slash", () => {
|
||||
const options: BkndAdminProps["config"] = {
|
||||
basepath: "/",
|
||||
admin_basepath: "/admin/",
|
||||
logo_return_path: "/",
|
||||
};
|
||||
|
||||
appReduced = new AppReduced(mockAppJson, options);
|
||||
const result = appReduced.getAbsolutePath("data");
|
||||
|
||||
expect(result).toBe("~/admin/data");
|
||||
expect(result).not.toContain("//");
|
||||
});
|
||||
|
||||
it("should handle settings path with admin_basepath trailing slash", () => {
|
||||
const options: BkndAdminProps["config"] = {
|
||||
basepath: "/",
|
||||
admin_basepath: "/admin/",
|
||||
logo_return_path: "/",
|
||||
};
|
||||
|
||||
appReduced = new AppReduced(mockAppJson, options);
|
||||
const result = appReduced.getSettingsPath(["general"]);
|
||||
|
||||
expect(result).toBe("~/admin/settings/general");
|
||||
expect(result).not.toContain("//");
|
||||
});
|
||||
});
|
||||
|
||||
describe("edge cases", () => {
|
||||
it("should handle undefined basepath", () => {
|
||||
const options: BkndAdminProps["config"] = {
|
||||
|
||||
Reference in New Issue
Block a user