[PR #8941] fix: handle trailing spaces in working directory paths #12916

Open
opened 2026-02-16 18:17:48 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8941

State: open
Merged: No


Summary

Fixes #8937 - OpenCode hangs when working directory has trailing space in name.

  • Added sanitizePath() utility function to detect and auto-fix problematic path characters
  • Validates for: trailing whitespace, leading whitespace, null bytes, empty paths
  • Shows warning to user when path issues are detected, then continues with sanitized path
  • Applied defense-in-depth at all directory entry points

Changes

File Change
src/util/filesystem.ts Added SanitizeResult interface and sanitizePath() function
src/cli/ui.ts Added warn() function for displaying warnings
src/cli/cmd/tui/thread.ts Sanitizes cwd at startup, warns user about path issues
src/cli/cmd/tui/worker.ts Sanitizes process.cwd() for event stream
src/project/instance.ts Sanitizes directory in Instance.provide()
src/server/server.ts Sanitizes directory in HTTP middleware
test/util/filesystem.test.ts Added 9 unit tests for sanitizePath()

Testing

  • All 742 existing tests pass
  • Added 9 new unit tests for sanitizePath() covering all edge cases
  • TypeScript type checking passes
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8941 **State:** open **Merged:** No --- ## Summary Fixes #8937 - OpenCode hangs when working directory has trailing space in name. - Added `sanitizePath()` utility function to detect and auto-fix problematic path characters - Validates for: trailing whitespace, leading whitespace, null bytes, empty paths - Shows warning to user when path issues are detected, then continues with sanitized path - Applied defense-in-depth at all directory entry points ## Changes | File | Change | |------|--------| | `src/util/filesystem.ts` | Added `SanitizeResult` interface and `sanitizePath()` function | | `src/cli/ui.ts` | Added `warn()` function for displaying warnings | | `src/cli/cmd/tui/thread.ts` | Sanitizes cwd at startup, warns user about path issues | | `src/cli/cmd/tui/worker.ts` | Sanitizes `process.cwd()` for event stream | | `src/project/instance.ts` | Sanitizes directory in `Instance.provide()` | | `src/server/server.ts` | Sanitizes directory in HTTP middleware | | `test/util/filesystem.test.ts` | Added 9 unit tests for `sanitizePath()` | ## Testing - All 742 existing tests pass - Added 9 new unit tests for `sanitizePath()` covering all edge cases - TypeScript type checking passes
yindo added the pull-request label 2026-02-16 18:17:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12916