[BUG] Legacy-encoded source files (Shift-JIS / EUC-KR / GBK) are dropped as "binary" and never reach the encoding detector
A file that is genuinely Shift-JIS (or EUC-KR, GBK, windows-1252…) is reported as binary and dropped from the pack, and the code says that is not what is supposed to happen.
// Buffer is not valid UTF-8. Run the full `isBinaryFile` check now to
// distinguish real binaries (PE/ELF/PNG/etc.) from legacy-encoded text
// (Shift-JIS, EUC-KR, GBK, …) that should still reach the slow path.— src/core/file/fileRead.ts:126-129
The check cannot make that distinction, and nothing overrides it, so the slow path the comment refers to never sees these files.
Repro
mkdir -p enc/src enc/notes && cd enc
PYTHONIOENCODING=utf-8 python - <<'PY'
jp = '// こんにちは世界\n'
big = ('// データベース接続を初期化して、クエリを実行します。\n'
'public void processOrder(int id){ repo.save(new Order(id,"注文")); }\n') * 30
open('src/Big.java', 'wb').write((jp + big).encode('shift_jis'))
open('src/Utf8.java', 'w', encoding='utf-8', newline='\n').write(jp + 'class U{}\n')
open('notes/euckr.txt', 'wb').write(('안녕하세요 세계\n' * 10).encode('euc_kr'))
open('notes/gbk.txt', 'wb').write(('你好世界,这是一个测试文件\n' * 10).encode('gbk'))
PY
echo '{"name":"enc-fixture","version":"1.0.0"}' > package.json
git init -q && git add -A && git commit -qm init
node node_modules/repomix/bin/repomix.cjs . -o packed.xml # v1.18.0, built from 9f01703aACTUAL — src/Utf8.java holds the same Japanese text as src/Big.java and is the only one packed:
Binary Files Detected:
3 files detected as binary by content inspection:
Total Files: 2 files$ grep -o 'path="[^"]*"' packed.xml
path="src/Utf8.java"
path="package.json"There is no flag that changes this: the files are gone from the output and only listed as binary.
Why the pre-screen cannot work for these encodings
isbinaryfile decides from at most MAX_BYTES = 512 bytes and treats every byte above 127 that is not part of a UTF-8 sequence as suspicious, returning binary above a 10% ratio (node_modules/isbinaryfile/lib/index.js:18,193-222). Double-byte text is essentially all high bytes, so the ratio is ~100% and the verdict is always binary — regardless of how clearly text it is.
Measured on those very buffers with repomix's own runtime dependencies:
| file | isBinaryFile |
jschardet.detect |
confidence | iconv.decode clean |
|---|---|---|---|---|
src/Big.java |
true |
SHIFT_JIS |
1.00 | yes |
notes/euckr.txt |
true |
EUC-KR |
0.99 | yes |
notes/gbk.txt |
true |
GB2312 |
0.99 | yes |
latin-1 prose (windows-1252) |
true |
windows-1252 |
0.95 | yes |
%PDF-1.4… + binary tail |
true |
windows-1255 |
0.25 | no (U+FFFD) |
src/Utf8.java |
false |
UTF-8 |
0.99 | yes |
The last two rows are the point: the detector already installed as a runtime dependency separates these cases perfectly on the very same buffers, and it is the reason jschardet and iconv-lite are in package.json at all. The binary verdict is consulted first and returned unconditionally at :129-132, so the detection path at :134-146 only ever runs for the files that needed it least.
Expected
Legacy-encoded text reaches the detection path and is packed decoded, which is what the comment at :126-129 describes and what output then shows. Real binaries keep being skipped.
Not previously reported: searching the tracker for shift-jis, shiftjis, euc-kr, gbk, legacy encoding, mojibake, isbinaryfile, iconv and encoding returns no open issue or PR. The closest prior art is #869 and #847, both closed, both about valid UTF-8 being wrongly called binary — and #869 is pinned by a test titled "should read file with low jschardet confidence (#869)" (tests/core/file/fileRead.test.ts:29), which shows low-confidence acceptance is deliberate on the existing slow path. No test asserts that Shift-JIS is binary, so this looks like an oversight in the pre-screen rather than a decision.
Source: yamadashy/repomix