Fix device ID parsing regression in Mithril 2.3.8
Device IDs containing literal % characters (e.g., "202BC1-CODA%2D5519-000000") are double-encoded in URLs. Mithril 2.3.8 incorrectly double-decodes route parameters, corrupting device IDs with special characters. Workaround: Extract device ID directly from window.location.hash and decode once to get the correct value. See: https://github.com/MithrilJS/mithril.js/issues/3064
This commit is contained in:
1 parent
087b95388f
commit
f9ee39dfd0
1 file changed
+29
-2
+29
-2
@@ -3,6 +3,29 @@ import { m } from "./components.ts";
|
|||||||
import config from "./config.ts";
|
import config from "./config.ts";
|
||||||
import * as store from "./store.ts";
|
import * as store from "./store.ts";
|
||||||
|
|
||||||
|
// Workaround for Mithril 2.3.8 regression
|
||||||
|
// https://github.com/MithrilJS/mithril.js/issues/3064
|
||||||
|
function getPathParamFromHash(hash: string, prefix: string): string | null {
|
||||||
|
if (!hash.startsWith(prefix)) return null;
|
||||||
|
|
||||||
|
const pathWithQuery = hash.slice(prefix.length);
|
||||||
|
|
||||||
|
// Stop at query string or hash fragment (mirrors Mithril's parsePathname)
|
||||||
|
const queryIdx = pathWithQuery.indexOf("?");
|
||||||
|
const hashIdx = pathWithQuery.indexOf("#");
|
||||||
|
let pathEnd = pathWithQuery.length;
|
||||||
|
if (queryIdx >= 0) pathEnd = Math.min(pathEnd, queryIdx);
|
||||||
|
if (hashIdx >= 0) pathEnd = Math.min(pathEnd, hashIdx);
|
||||||
|
|
||||||
|
const rawPath = pathWithQuery.slice(0, pathEnd);
|
||||||
|
|
||||||
|
// Normalize: collapse slashes, remove trailing slash (matches Mithril)
|
||||||
|
const normalizedPath = rawPath.replace(/\/{2,}/g, "/").replace(/\/$/, "");
|
||||||
|
|
||||||
|
// Decode once (Mithril already decoded with decodeURIComponentSafe)
|
||||||
|
return decodeURIComponent(normalizedPath);
|
||||||
|
}
|
||||||
|
|
||||||
export function init(
|
export function init(
|
||||||
args: Record<string, unknown>,
|
args: Record<string, unknown>,
|
||||||
): Promise<Record<string, unknown>> {
|
): Promise<Record<string, unknown>> {
|
||||||
@@ -12,9 +35,13 @@ export function init(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deviceId =
|
||||||
|
getPathParamFromHash(window.location.hash, "#!/devices/") ??
|
||||||
|
(args.id as string);
|
||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
deviceId: args.id,
|
deviceId: deviceId,
|
||||||
deviceFilter: ["=", ["PARAM", "DeviceID.ID"], args.id],
|
deviceFilter: ["=", ["PARAM", "DeviceID.ID"], deviceId],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user