Skip to content

Commit 589c1cb

Browse files
committed
bug: space in folder and file name #2361
1 parent 4c8fec6 commit 589c1cb

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/core/mentions/__tests__/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Detailed commit message with multiple lines
156156
jest.spyOn(fs, "stat").mockResolvedValue({ isFile: () => true, isDirectory: () => false } as any)
157157

158158
// Test with a file path containing escaped spaces
159-
const filePath = "/path/with\\ spaces/my\\ file.txt"
159+
const filePath = "/path/with\ spaces/my\ file.txt"
160160

161161
// First, verify that the regex pattern correctly matches the entire path
162162
// Import the regex pattern directly to test it
@@ -188,7 +188,7 @@ Detailed commit message with multiple lines
188188
jest.spyOn(fs, "stat").mockResolvedValue({ isFile: () => false, isDirectory: () => true } as any)
189189

190190
// Test with a folder path containing escaped spaces
191-
const folderPath = "/folder\\ with\\ spaces/"
191+
const folderPath = "/folder\ with\ spaces/"
192192

193193
// First, verify that the regex pattern correctly matches the entire path
194194
const { mentionRegexGlobal } = require("../../../shared/context-mentions")
@@ -214,7 +214,7 @@ Detailed commit message with multiple lines
214214
jest.spyOn(fs, "stat").mockResolvedValue({ isFile: () => true, isDirectory: () => false } as any)
215215

216216
// Test with a deeply nested path containing multiple escaped spaces
217-
const filePath = "/root\\ dir/my\\ documents/project\\ files/important\\ notes/final\\ draft\\ v2.txt"
217+
const filePath = "/root\ dir/my\ documents/project\ files/important\ notes/final\ draft\ v2.txt"
218218

219219
// Verify the regex pattern correctly matches the entire path
220220
const { mentionRegexGlobal } = require("../../../shared/context-mentions")

src/core/mentions/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export async function parseMentions(
4747
): Promise<string> {
4848
const mentions: Set<string> = new Set()
4949
let parsedText = text.replace(mentionRegexGlobal, (match, mention) => {
50-
// Unescape spaces in the mention (convert "\\s" to " ")
51-
const unescapedMention = mention.replace(/\\\\\s/g, " ")
50+
// Unescape spaces in the mention (convert "\s" to " ")
51+
const unescapedMention = mention.replace(/\\\s/g, " ")
5252
mentions.add(unescapedMention)
5353

5454
if (unescapedMention.startsWith("http")) {

src/shared/context-mentions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Mention regex:
1818
- `|`: Logical OR.
1919
- `\w+:\/\/`:
2020
- **Protocol (`\w+://`)**: Matches URLs that start with a word character sequence followed by '://', such as 'http://', 'https://', 'ftp://', etc.
21-
- `[^\s\r\n]*?(?:\\\\\s[^\s\r\n]*?)*?(?=\s*$|\s+@|[.,;:!?](?=[\s\r\n]|$))`:
21+
- `[^\s\r\n]*?(?:\\[\s][^\s\r\n]*?)*?(?=\s*$|\s+@|[.,;:!?](?=[\s\r\n]|$))`:
2222
- **Character Pattern**: Matches any characters except whitespace and line breaks.
23-
- **Escaped Spaces**: The `(?:\\\\\s[^\s\r\n]*?)*?` part allows for escaped spaces (like `\\s`) in the path.
23+
- **Escaped Spaces**: The `(?:\\[\s][^\s\r\n]*?)*?` part allows for escaped spaces (like `\s`) in the path.
2424
- **Followed by a lookahead**: Ensures the match ends at the end of the line, before another @ symbol, or before punctuation followed by whitespace or end of line.
25-
- **This handles paths with escaped spaces (e.g., `my\\ folder/my\\ file.txt`)**.
25+
- **This handles paths with escaped spaces (e.g., `my\ folder/my\ file.txt`)**.
2626
- **Non-Greedy (`*?`)**: Ensures the smallest possible match.
2727
- `|`: Logical OR.
2828
- `problems\b`:
@@ -41,7 +41,7 @@ Mention regex:
4141
4242
- **Summary**:
4343
- The regex effectively matches:
44-
- Mentions that are file or folder paths starting with '/' and can contain escaped spaces within the path (e.g., 'my\\ folder/my\\ file.txt').
44+
- Mentions that are file or folder paths starting with '/' and can contain escaped spaces within the path (e.g., 'my\ folder/my\ file.txt').
4545
The regex properly handles paths with escaped spaces and ensures the entire path is captured.
4646
- URLs that start with a protocol (like 'http://') followed by any non-whitespace characters (including query parameters).
4747
- The exact word 'problems'.
@@ -54,7 +54,7 @@ Mention regex:
5454
5555
*/
5656
export const mentionRegex =
57-
/@((?:\/|\w+:\/\/)[^\s\r\n]*?(?:\\\\\s[^\s\r\n]*?)*?(?=\s*$|\s+@|[.,;:!?](?=[\s\r\n]|$))|[a-f0-9]{7,40}\b|problems\b|git-changes\b|terminal\b)(?=[.,;:!?]?(?=[\s\r\n]|$))/
57+
/@((?:\/|\w+:\/\/)[^\s\r\n]*?(?:\\[\s][^\s\r\n]*?)*?(?=\s*$|\s+@|[.,;:!?](?=[\s\r\n]|$))|[a-f0-9]{7,40}\b|problems\b|git-changes\b|terminal\b)(?=[.,;:!?]?(?=[\s\r\n]|$))/
5858
export const mentionRegexGlobal = new RegExp(mentionRegex.source, "g")
5959

6060
export interface MentionSuggestion {

webview-ui/src/utils/__tests__/context-mentions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,16 @@ describe("shouldShowContextMenu", () => {
375375

376376
it("should return true for file paths with escaped spaces", () => {
377377
// Test with a file path containing escaped spaces
378-
expect(shouldShowContextMenu("@/path/to/my\\ file.txt", 20)).toBe(true)
378+
expect(shouldShowContextMenu("@/path/to/my\ file.txt", 20)).toBe(true)
379379
})
380380

381381
it("should return true for folder paths with escaped spaces", () => {
382382
// Test with a folder path containing escaped spaces
383-
expect(shouldShowContextMenu("@/path/to/my\\ folder/", 20)).toBe(true)
383+
expect(shouldShowContextMenu("@/path/to/my\ folder/", 20)).toBe(true)
384384
})
385385

386386
it("should return true for nested paths with multiple escaped spaces", () => {
387387
// Test with a deeply nested path containing multiple escaped spaces
388-
expect(shouldShowContextMenu("@/root\\ dir/my\\ documents/project\\ files/file.txt", 50)).toBe(true)
388+
expect(shouldShowContextMenu("@/root\ dir/my\ documents/project\ files/file.txt", 50)).toBe(true)
389389
})
390390
})

0 commit comments

Comments
 (0)