Skip to content

Incorrect escaping of spaces in file paths causes mention highlighting and file access failures #2564

@Yikai-Liao

Description

@Yikai-Liao

App Version

3.11.14

API Provider

OpenRouter

Model Used

Claude 3.7 Sonnet

Actual vs. Expected Behavior

Actual Behavior:

  • When a file path contains spaces or special characters, the @ mention highlighting doesn't work correctly
  • The system fails to properly read or access files with spaces in their paths when referenced using the @ mention syntax
  • Multiple backslashes are added inconsistently, causing path resolution issues
  • In some cases, file paths with existing escaped spaces get double-escaped incorrectly

Expected Behavior:

  • File paths with spaces should be properly escaped with backslashes
  • The @ mention highlighting should work correctly for all file paths regardless of spaces or special characters
  • Files with spaces in their paths should be correctly accessed when referenced using the @ mention syntax
  • Already escaped spaces should not be double-escaped in an incorrect manner

Detailed Steps to Reproduce

  1. Create a folder and a file with spaces in their names (e.g., folder with spaces/file with spaces.txt)
  2. In the editor, type @ to trigger the mention functionality
  3. Select the file with spaces from the file list
  4. Observe that the file path is incorrectly escaped in the editor
  5. Try to access the file by clicking on the mention link
  6. Observe that the file cannot be opened or is opened incorrectly

Code to demonstrate the issue:

// Create a path with spaces
const path = "/path/to/folder with spaces/file with spaces.txt";

// Convert to mention path
const mentionPath = convertToMentionPath(path, "/path/to");

// Expected: "@/folder\ with\ spaces/file\ with\ spaces.txt"
// Actual: Incorrect escaping that varies depending on context
console.log(mentionPath);

// When using insertMention, the spaces are handled inconsistently
const result = insertMention("Check this file: ", cursorPosition, mentionPath.substring(1));

Relevant API Request Output

Additional Context

The issue occurs due to multi-level escaping problems in two key utility functions:

  1. convertToMentionPath in path-mentions.ts - Fails to properly handle paths with spaces and existing escaped spaces
  2. insertMention in context-mentions.ts - Doesn't consistently handle the escaped paths

This issue affects both Windows and Unix-style paths. The problem is particularly severe when files already contain escaped spaces, as the escaping logic doesn't account for this case.

The bug impacts users trying to reference files with spaces in their paths, which is a common scenario especially in project names, documentation folders, and descriptive file naming schemes.

Debug info:

  • Operating System: Affects all platforms (Windows, macOS, Linux)
  • Plugin version: [Your version number]
  • Reproducible with: Any file paths containing spaces

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions