[PR #13718] cmd: use shell tokenizer for image file paths #40235

Open
opened 2026-04-23 01:11:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13718
Author: @KhushAhuja
Created: 1/14/2026
Status: 🔄 Open

Base: mainHead: fix/shell-tokenizer-path


📝 Commits (1)

  • 0be60fd cmd: use shell tokenizer for image file paths

📊 Changes

4 files changed (+64 additions, -17 deletions)

View changed files

📝 cmd/interactive.go (+7 -17)
📝 cmd/interactive_test.go (+54 -0)
📝 go.mod (+1 -0)
📝 go.sum (+2 -0)

📄 Description

Fixes Issue

Fixes #10333

Description

This PR replaces the manual strings.NewReplacer logic in normalizeFilePath with a proper shell tokenizer (google/shlex).

The Problem:
Currently, image file paths are cleaned using a manual list of escaped characters. This causes silent failures for characters not in that list, such as double quotes (") and exclamation marks (!). For example, a file named test_!_"image".jpg fails to load without any error message (EOF).

The Solution:
Instead of maintaining a growing list of replacement rules, this change uses google/shlex to handle all POSIX shell escaping generically. This makes the CLI robust against any valid filename generated by a shell.

Dependency Justification

  • Added: github.com/google/shlex
  • Why: As per CONTRIBUTING.md, dependencies should be added sparingly. In this case, correctly parsing shell-escaped strings (handling nested quotes, backslashes, and special chars) is complex and error-prone to implement from scratch. google/shlex is a small, standard, battle-tested library that solves this specific problem safely, reducing the long-term maintenance burden of interactive.go.

Testing

Added table-driven unit tests in cmd/interactive_test.go verifying:

  • New Edge Cases: Double quotes ("), Exclamation marks (!), and @ symbols.
  • Backward Compatibility: Verified that previously handled characters ((, ), $, &, etc.) still parse correctly.
  • Manual Verification: Verified locally on macOS (zsh) that ollama run moondream now successfully loads images with complex names like test_!_"image".jpg.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13718 **Author:** [@KhushAhuja](https://github.com/KhushAhuja) **Created:** 1/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/shell-tokenizer-path` --- ### 📝 Commits (1) - [`0be60fd`](https://github.com/ollama/ollama/commit/0be60fdc54cb9dfbd12dc68e7effe0f44a077f51) cmd: use shell tokenizer for image file paths ### 📊 Changes **4 files changed** (+64 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `cmd/interactive.go` (+7 -17) 📝 `cmd/interactive_test.go` (+54 -0) 📝 `go.mod` (+1 -0) 📝 `go.sum` (+2 -0) </details> ### 📄 Description ### Fixes Issue Fixes #10333 ### Description This PR replaces the manual `strings.NewReplacer` logic in `normalizeFilePath` with a proper shell tokenizer (`google/shlex`). **The Problem:** Currently, image file paths are cleaned using a manual list of escaped characters. This causes silent failures for characters not in that list, such as double quotes (`"`) and exclamation marks (`!`). For example, a file named `test_!_"image".jpg` fails to load without any error message (EOF). **The Solution:** Instead of maintaining a growing list of replacement rules, this change uses `google/shlex` to handle all POSIX shell escaping generically. This makes the CLI robust against any valid filename generated by a shell. ### Dependency Justification * **Added:** `github.com/google/shlex` * **Why:** As per `CONTRIBUTING.md`, dependencies should be added sparingly. In this case, correctly parsing shell-escaped strings (handling nested quotes, backslashes, and special chars) is complex and error-prone to implement from scratch. `google/shlex` is a small, standard, battle-tested library that solves this specific problem safely, reducing the long-term maintenance burden of `interactive.go`. ### Testing Added table-driven unit tests in `cmd/interactive_test.go` verifying: * **New Edge Cases:** Double quotes (`"`), Exclamation marks (`!`), and `@` symbols. * **Backward Compatibility:** Verified that previously handled characters (`(`, `)`, `$`, `&`, etc.) still parse correctly. * **Manual Verification:** Verified locally on macOS (zsh) that `ollama run moondream` now successfully loads images with complex names like `test_!_"image".jpg`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-23 01:11:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#40235