google-gemini / google-gemini/gemini-cli

isEmpty misclassifies BOM-encoded whitespace-only plan files as non-empty

Open Beginner friendly
#29,142 4 comments 0 reactions 0 assignees View on GitHub
area/core effort/small status/bot-triaged
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

### What happened?

`validatePlanContent()` accepts a whitespace-only plan file when the file is encoded as UTF-16 with a BOM.

On current `main`, `isEmpty()` detects and removes the BOM but then always decodes the sampled bytes with UTF-8. UTF-16 whitespace bytes therefore leave NUL characters after decoding, and `trim()` reports the file as non-empty.

A focused regression test reproduces the problem:

```ts
it('should return true for a UTF-16 LE file containing only whitespace', async () => {
const testFile = path.join(tempRootDir, 'utf16le-whitespace.txt');
actualNodeFs.writeFileSync(
testFile,
Buffer.concat([
Buffer.from([0xff, 0xfe]),
Buffer.from(' \n\t', 'utf16le'),
]),
);

expect(await isEmpty(testFile)).toBe(true);
});
```

Run with:

```console
npx -y -p node@20.19.0 -c 'node --version && npm test -w @google/gemini-cli-core -- src/utils/fileUtils.test.ts'
```

Result: the new assertion fails with `expected false to be true`; the other 93 tests in the file pass.

The same implementation branch handles UTF-16 BE and UTF-32 BOMs, but still calls `.toString('utf8')`, so those encodings have the same underlying mismatch.

### What did you expect to happen?

`isEmpty()` should decode the sampled bytes according to the detected BOM before trimming, matching its documented behavior and the existing BOM-aware decoding support in `fileUtils.ts`. A BOM-encoded file containing only whitespace should be rejected by `validatePlanContent()` as empty.

### Client information

Client Information

This is a source-level unit-test reproduction rather than an interactive-session report.

- Repository commit: `0bd1d43`
- Package: `@google/gemini-cli-core@0.59.0-nightly.20260825.g812f7a2bc`
- Node.js: `v20.19.0`
- Platform: macOS

### Anything else we need to know?

I searched open and closed issues and pull requests for `isEmpty`, UTF-16/UTF-32, BOM, and whitespace combinations and did not find an existing report or fix. If maintainers confirm the intended behavior, I would be happy to prepare a focused regression test and patch linked to this issue.

Contributor guide

Open the contributing guide

Research direction

Start with src/utils/fileUtils.ts and the isEmpty() implementation, then run src/utils/fileUtils.test.ts using the Node 20 command from the issue. Verify that BOM-encoded UTF-16 and UTF-32 whitespace samples are decoded according to their detected encoding before trimming. Done means the focused regression test passes and validatePlanContent() treats those files as empty.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.