diff --git a/src/client-ua-registry.ts b/src/client-ua-registry.ts index 48910b16d2..29903b3efe 100644 --- a/src/client-ua-registry.ts +++ b/src/client-ua-registry.ts @@ -19,6 +19,7 @@ import { isCodexClient } from "./codex-compact.js"; import { sniffScanClient } from "./thirdparty-scan.js"; +import { safePrefix } from "./text-safe.js"; // Read directly (wire literal) instead of via plugin.ts — same discipline as // codex-compact.ts / session-id.ts: importing plugin.ts back into the request @@ -62,7 +63,7 @@ export function clientFamilyOf(headers: Record): void { const raw = headerString(headers, "user-agent"); if (!raw || !raw.trim()) return; - const ua = raw.trim().slice(0, UA_MAX_CHARS); + const ua = safePrefix(raw.trim(), UA_MAX_CHARS); const now = Date.now(); let fam = families.get(clientFamilyOf(headers)); if (!fam) { diff --git a/tests/web-diagnostics-unicode.test.ts b/tests/web-diagnostics-unicode.test.ts index 138a2e824d..12e651ed93 100644 --- a/tests/web-diagnostics-unicode.test.ts +++ b/tests/web-diagnostics-unicode.test.ts @@ -5,6 +5,7 @@ import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; import type http from "node:http"; import { tmpdir } from "node:os"; import path from "node:path"; +import { recordClientUa, _resetClientUaRegistryForTest } from "../src/client-ua-registry.js"; import { recordConflict } from "../src/conflict-watch.js"; import { closeLogger, configureLogger } from "../src/logger.js"; import { SessionStore, _setStoreForTest } from "../src/persist.js"; @@ -15,7 +16,7 @@ import { makeOpts } from "./corrupt-index-child.js"; const ENV_KEYS = ["BILI_CONFIG_FILE", "BILI_SESSIONS_DIR", "DSH_HOME", "XDG_STATE_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME"] as const; type Report = Awaited>; -type Source = "storage log" | "conflict log" | "config" | "conflict detail" | "topic"; +type Source = "storage log" | "conflict log" | "config" | "conflict detail" | "topic" | "user-agent"; type Boundary = "split pair" | "whole pair" | "ASCII"; interface Fixture { config: string; log: string } @@ -38,12 +39,14 @@ async function withFixture(fn: (fixture: Fixture) => Promise): Promise { await withFixture(async (fixture) => {