mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-28 06:00:38 +00:00
* fix(i18n): survive a malformed locale cookie getLocaleFromCookie decoded the raw cookie value without a guard, so a malformed percent-encoding threw URIError during locale bootstrap and in formatTimeAgo. It also split the cookie on every "=", truncating values that contain one. Decode defensively and split on the first "=" only. * fix(i18n): normalize the cookie locale in formatTimeAgo The second caller of getLocaleFromCookie cast the raw value to Locale, so a malformed-but-known-prefixed cookie skipped normalization. Normalize it like useI18n does, and cover the malformed and valid cookie paths. --------- Co-authored-by: 一片一片 <192845873+gdut4140@users.noreply.github.com>
18 lines
533 B
TypeScript
18 lines
533 B
TypeScript
import { afterEach, expect, test } from "@rstest/core";
|
|
|
|
import { formatTimeAgo } from "@/core/utils/datetime";
|
|
|
|
afterEach(() => {
|
|
document.cookie = "locale=; max-age=0; path=/";
|
|
});
|
|
|
|
test("falls back to a known locale for a malformed locale cookie", () => {
|
|
document.cookie = "locale=zh%FF; path=/";
|
|
expect(() => formatTimeAgo(Date.now() - 5_000)).not.toThrow();
|
|
});
|
|
|
|
test("uses the locale from the cookie", () => {
|
|
document.cookie = "locale=zh-CN; path=/";
|
|
expect(formatTimeAgo(Date.now() - 5_000)).toContain("前");
|
|
});
|