Skip to content

feat: Ensure ClaudeCodeAdd correctly escapes file path argument#210

Open
HsiuCL wants to merge 1 commit intocoder:mainfrom
HsiuCL:feat/escaped-args-main
Open

feat: Ensure ClaudeCodeAdd correctly escapes file path argument#210
HsiuCL wants to merge 1 commit intocoder:mainfrom
HsiuCL:feat/escaped-args-main

Conversation

@HsiuCL
Copy link

@HsiuCL HsiuCL commented Mar 10, 2026

Summary

Fix ClaudeCodeAdd command to correctly handle file paths containing spaces by adding a backslash-escape-aware argument parser. Previously, vim.split(args, "%s+") would incorrectly split escaped paths like file\ name.lua into separate tokens, breaking file resolution and potentially misinterpreting path fragments as line numbers.

Changes

Escaped argument parser

  • Added parse_escaped_args() function that respects backslash-escaped spaces (\ ) and escaped backslashes (\\) when splitting command-line arguments
  • Replaced vim.split(opts.args, "%s+") with parse_escaped_args(opts.args) in the ClaudeCodeAdd command handler
  • Unescaped whitespace is treated as a delimiter; \ is preserved as a literal space within a token

Test coverage

  • Added 5 new tests under an "escaped path handling" describe block:
    • Backslash-escaped spaces in file paths are correctly parsed
    • Escaped spaces are not confused with argument delimiters (e.g., file\ 1 is treated as a path, not path + line number)
    • Escaped paths work correctly with line range arguments
    • Escaped paths work correctly with a start-line-only argument
    • Non-escaped paths continue to work as before

Notable Details

  • The parser is intentionally minimal — it only handles \ (escaped space) and \\ (escaped backslash). Other escape sequences pass the backslash through unchanged, matching shell-like conventions.
  • No breaking changes: paths without spaces behave identically to the previous implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant