mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 05:45:51 +00:00
- errors.test.ts: 28 tests (isAbortError, toError, errorMessage, getErrnoCode, isFsInaccessible, classifyAxiosError 等) - shellRuleMatching.test.ts: 22 tests (permissionRuleExtractPrefix, hasWildcards, matchWildcardPattern, parsePermissionRule 等) - argumentSubstitution.test.ts: 18 tests (parseArguments, parseArgumentNames, generateProgressiveArgumentHint, substituteArguments) - CircularBuffer.test.ts: 12 tests (add, addAll, getRecent, toArray, clear, length) - sanitization.test.ts: 14 tests (partiallySanitizeUnicode, recursivelySanitizeUnicode) - slashCommandParsing.test.ts: 8 tests (parseSlashCommand) - contentArray.test.ts: 6 tests (insertBlockAfterToolResults) - objectGroupBy.test.ts: 5 tests (objectGroupBy) 总计:781 tests / 40 files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
partiallySanitizeUnicode,
|
|
recursivelySanitizeUnicode,
|
|
} from "../sanitization";
|
|
|
|
// ─── partiallySanitizeUnicode ───────────────────────────────────────────
|
|
|
|
describe("partiallySanitizeUnicode", () => {
|
|
test("preserves normal ASCII text", () => {
|
|
expect(partiallySanitizeUnicode("hello world")).toBe("hello world");
|
|
});
|
|
|
|
test("preserves CJK characters", () => {
|
|
expect(partiallySanitizeUnicode("你好世界")).toBe("你好世界");
|
|
});
|
|
|
|
test("removes zero-width spaces", () => {
|
|
expect(partiallySanitizeUnicode("hello\u200Bworld")).toBe("helloworld");
|
|
});
|
|
|
|
test("removes BOM", () => {
|
|
expect(partiallySanitizeUnicode("\uFEFFhello")).toBe("hello");
|
|
});
|
|
|
|
test("removes directional formatting", () => {
|
|
expect(partiallySanitizeUnicode("hello\u202Aworld")).toBe("helloworld");
|
|
});
|
|
|
|
test("removes private use area characters", () => {
|
|
expect(partiallySanitizeUnicode("hello\uE000world")).toBe("helloworld");
|
|
});
|
|
|
|
test("handles empty string", () => {
|
|
expect(partiallySanitizeUnicode("")).toBe("");
|
|
});
|
|
|
|
test("handles string with only dangerous characters", () => {
|
|
const result = partiallySanitizeUnicode("\u200B\u200C\u200D\uFEFF");
|
|
expect(result.length).toBeLessThanOrEqual(1); // ZWJ may survive NFKC
|
|
});
|
|
});
|
|
|
|
// ─── recursivelySanitizeUnicode ─────────────────────────────────────────
|
|
|
|
describe("recursivelySanitizeUnicode", () => {
|
|
test("sanitizes string values", () => {
|
|
expect(recursivelySanitizeUnicode("hello\u200Bworld")).toBe("helloworld");
|
|
});
|
|
|
|
test("sanitizes array elements", () => {
|
|
const result = recursivelySanitizeUnicode(["a\u200Bb", "c\uFEFFd"]);
|
|
expect(result).toEqual(["ab", "cd"]);
|
|
});
|
|
|
|
test("sanitizes object values recursively", () => {
|
|
const result = recursivelySanitizeUnicode({
|
|
key: "val\u200Bue",
|
|
nested: { inner: "te\uFEFFst" },
|
|
});
|
|
expect(result).toEqual({ key: "value", nested: { inner: "test" } });
|
|
});
|
|
|
|
test("preserves numbers", () => {
|
|
expect(recursivelySanitizeUnicode(42)).toBe(42);
|
|
});
|
|
|
|
test("preserves booleans", () => {
|
|
expect(recursivelySanitizeUnicode(true)).toBe(true);
|
|
});
|
|
|
|
test("preserves null", () => {
|
|
expect(recursivelySanitizeUnicode(null)).toBeNull();
|
|
});
|
|
});
|