Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ingest/chunker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export function isBinaryChunk(text: string): boolean {
// Count U+FFFD replacement characters — strong signal of binary source
let replacementCount = 0;
for (let i = 0; i < text.length; i++) {
if (text.charCodeAt(i) === 0xFFFD) {
replacementCount++;
}
const c = text.charCodeAt(i);
if (c === 0) return true; // NUL byte → immediate binary signal
if (c === 0xFFFD) replacementCount++;
}

// If >10% of characters are replacement chars, the source was likely binary
Expand Down
9 changes: 9 additions & 0 deletions test/ingest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,13 @@ describe("isBinaryChunk (per-chunk validation)", () => {
test("real text with no replacement chars (should NOT be flagged)", () => {
expect(isBinaryChunk("const x = 42;\nexport default x;\n")).toBe(false);
});

test("chunk with embedded null byte (should be flagged)", () => {
const text = "normal text\u0000with null byte";
expect(isBinaryChunk(text)).toBe(true);
});

test("chunk with null byte at start", () => {
expect(isBinaryChunk("\u0000hello")).toBe(true);
});
});
Loading