48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
/** 商品下单跨登录的镜像选择续接;Symbol 用作组件树注入键,不将状态暴露为全局字符串键。 */
|
|
var e = Symbol(`order-login-continuation`);
|
|
// 只接受正安全整数;字符串须为规范十进制形式,避免前导零或指数写法产生歧义。
|
|
function t(e) {
|
|
if (typeof e != `number` && typeof e != `string`) return;
|
|
let t = Number(e);
|
|
if (!(
|
|
!Number.isSafeInteger(t) ||
|
|
t <= 0 ||
|
|
(typeof e == `string` && String(t) !== e)
|
|
))
|
|
return t;
|
|
}
|
|
function n(e) {
|
|
let t = decodeURIComponent(e);
|
|
return (
|
|
t.startsWith(`/`) &&
|
|
!t.startsWith(`//`) &&
|
|
// eslint-disable-next-line no-control-regex -- 安全边界:拒绝订单续接路径中的控制字符。
|
|
!/[\\\u0000-\u0020\u007f]/.test(t)
|
|
);
|
|
}
|
|
/** 校验站内回跳并替换 order_image;无效镜像参数被删除,无效路径统一回商品列表。 */
|
|
function r(e, r) {
|
|
try {
|
|
if (
|
|
typeof e != `string` ||
|
|
// eslint-disable-next-line no-control-regex -- 安全边界:解码后仍须拒绝控制字符绕过。
|
|
/[\\\u0000-\u0020\u007f]/.test(e) ||
|
|
!n(e.split(/[?#]/, 1)[0] || ``)
|
|
)
|
|
return `/products`;
|
|
let i = new URL(e, `https://console.invalid`);
|
|
if (i.origin !== `https://console.invalid` || !n(i.pathname))
|
|
return `/products`;
|
|
let a = t(r);
|
|
return (
|
|
a === void 0
|
|
? i.searchParams.delete(`order_image`)
|
|
: i.searchParams.set(`order_image`, String(a)),
|
|
`${i.pathname}${i.search}${i.hash}`
|
|
);
|
|
} catch {
|
|
return `/products`;
|
|
}
|
|
}
|
|
export { r as n, t as r, e as t };
|