fix(core): replace custom binary detection with isbinaryfile to correctly handle UTF-8 (U+FFFD) (#25297)

This commit is contained in:
Anjaligarhwal
2026-04-14 00:28:18 +05:30
committed by GitHub
parent a05c5ed56a
commit ea36ccb567
4 changed files with 36 additions and 38 deletions
+19
View File
@@ -286,6 +286,25 @@ describe('fileUtils', () => {
}
expect(await isBinaryFile(filePathForBinaryTest)).toBe(false);
});
it('should return false for a source file containing literal U+FFFD (replacement character)', async () => {
const content =
'// Rust-style source\npub const UNICODE_REPLACEMENT_CHAR: char = \'\uFFFD\';\nlet s = "\uFFFD\uFFFD\uFFFD";\n';
actualNodeFs.writeFileSync(filePathForBinaryTest, content, 'utf8');
expect(await isBinaryFile(filePathForBinaryTest)).toBe(false);
});
it('should return false for a file with mixed CJK, emoji, and U+FFFD content', async () => {
const content = '\uFFFD\uFFFD hello \u4e16\u754c \uD83D\uDE00\n';
actualNodeFs.writeFileSync(filePathForBinaryTest, content, 'utf8');
expect(await isBinaryFile(filePathForBinaryTest)).toBe(false);
});
it('should return true for a file with dense invalid UTF-8 byte sequences', async () => {
const binaryContent = Buffer.alloc(128, 0x80);
actualNodeFs.writeFileSync(filePathForBinaryTest, binaryContent);
expect(await isBinaryFile(filePathForBinaryTest)).toBe(true);
});
});
describe('BOM detection and encoding', () => {