[PR #11870] fix(tui): Handle file paths with hashtags #13965

Closed
opened 2026-02-16 18:18:47 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: No


What does this PR do?

This PR fixes #11790, improving the robustness of file path handling and line range parsing in the TUI autocomplete component.

  • Fixed Line Range Parsing: Updated extractLineRange to only treat a # as a separator if it is followed by a valid line range pattern (e.g., #123 or #123-456). This prevents filenames containing # (like file#name.txt or temp#dir/file#name.txt) from being incorrectly truncated.
  • Refactored Logic: removeLineRange now utilizes extractLineRange internally, ensuring consistent parsing behavior across the component.
  • Safe URL Construction: Replaced manual file:// string concatenation with pathToFileURL(path.resolve(...)). This ensures that special characters in file paths (spaces, #, ?, etc.) are properly percent-encoded according to URI standards, preventing broken file links in the TUI.

How did you verify your code works?

  • Create a sample temp directory.
mkdir temp
cd temp
echo -e "hello world\nhello world again\nand again" > "file#name.txt"
mkdir "temp#dir"
cp "file#name.txt" "temp#dir/file#name.txt"
  • Run opencode and tag both files, asking if they are same. The model should say that they have the same content.

Images

image
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11870 **State:** closed **Merged:** No --- ### What does this PR do? This PR fixes #11790, improving the robustness of file path handling and line range parsing in the TUI autocomplete component. - Fixed Line Range Parsing: Updated extractLineRange to only treat a `#` as a separator if it is followed by a valid line range pattern (e.g., `#123` or `#123-456`). This prevents filenames containing `#` (like `file#name.txt` or `temp#dir/file#name.txt`) from being incorrectly truncated. - Refactored Logic: removeLineRange now utilizes extractLineRange internally, ensuring consistent parsing behavior across the component. - Safe URL Construction: Replaced manual file:// string concatenation with pathToFileURL(path.resolve(...)). This ensures that special characters in file paths (spaces, #, ?, etc.) are properly percent-encoded according to URI standards, preventing broken file links in the TUI. ### How did you verify your code works? - Create a sample temp directory. ```sh mkdir temp cd temp echo -e "hello world\nhello world again\nand again" > "file#name.txt" mkdir "temp#dir" cp "file#name.txt" "temp#dir/file#name.txt" ``` - Run opencode and tag both files, asking if they are same. The model should say that they have the same content. ### Images <img width="2880" height="1800" alt="image" src="https://github.com/user-attachments/assets/9a7d2985-4a8c-42f2-a505-96c69e3f99d7" />
yindo added the pull-request label 2026-02-16 18:18:47 -05:00
yindo closed this issue 2026-02-16 18:18:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13965