Skip to content

Commit fabbbc1

Browse files
committed
fix: support Unicode characters in slash commands
- Updated commandRegexGlobal to include Unicode ranges for Chinese, Japanese, and Korean characters - Added comprehensive test cases for CJK characters and mixed character commands - Fixes #7240: slash commands now work with Chinese file names and other Unicode characters
1 parent 11c454f commit fabbbc1

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/__tests__/command-mentions.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,65 @@ npm install
280280
}
281281
})
282282
})
283+
284+
it("should match commands with Chinese characters", () => {
285+
const commandRegex =
286+
/(?:^|\s)\/([a-zA-Z0-9_\.\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]+)(?=\s|$)/g
287+
288+
const chinesePatterns = [
289+
"/中文命令",
290+
"/测试文件",
291+
"/配置文件",
292+
"/部署脚本",
293+
"Use /中文 command",
294+
"Run /测试 now",
295+
]
296+
297+
chinesePatterns.forEach((pattern) => {
298+
const matches = pattern.match(commandRegex)
299+
expect(matches).toBeTruthy()
300+
expect(matches?.length).toBeGreaterThan(0)
301+
})
302+
})
303+
304+
it("should match commands with Japanese characters", () => {
305+
const commandRegex =
306+
/(?:^|\s)\/([a-zA-Z0-9_\.\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]+)(?=\s|$)/g
307+
308+
const japanesePatterns = ["/テスト", "/ファイル", "/デプロイ", "Use /日本語 command", "Run /テスト now"]
309+
310+
japanesePatterns.forEach((pattern) => {
311+
const matches = pattern.match(commandRegex)
312+
expect(matches).toBeTruthy()
313+
expect(matches?.length).toBeGreaterThan(0)
314+
})
315+
})
316+
317+
it("should match commands with Korean characters", () => {
318+
const commandRegex =
319+
/(?:^|\s)\/([a-zA-Z0-9_\.\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]+)(?=\s|$)/g
320+
321+
const koreanPatterns = ["/테스트", "/파일", "/배포", "Use /한국어 command", "Run /테스트 now"]
322+
323+
koreanPatterns.forEach((pattern) => {
324+
const matches = pattern.match(commandRegex)
325+
expect(matches).toBeTruthy()
326+
expect(matches?.length).toBeGreaterThan(0)
327+
})
328+
})
329+
330+
it("should match commands with mixed characters", () => {
331+
const commandRegex =
332+
/(?:^|\s)\/([a-zA-Z0-9_\.\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]+)(?=\s|$)/g
333+
334+
const mixedPatterns = ["/test中文", "/deploy部署", "/file文件123", "/テストtest", "/한국어korean"]
335+
336+
mixedPatterns.forEach((pattern) => {
337+
const matches = pattern.match(commandRegex)
338+
expect(matches).toBeTruthy()
339+
expect(matches?.length).toBe(1)
340+
})
341+
})
283342
})
284343

285344
describe("command mention text transformation", () => {

src/shared/context-mentions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export const mentionRegex =
5858
export const mentionRegexGlobal = new RegExp(mentionRegex.source, "g")
5959

6060
// Regex to match command mentions like /command-name anywhere in text
61-
export const commandRegexGlobal = /(?:^|\s)\/([a-zA-Z0-9_\.-]+)(?=\s|$)/g
61+
// Updated to support Unicode characters including Chinese, Japanese, Korean, etc.
62+
export const commandRegexGlobal =
63+
/(?:^|\s)\/([a-zA-Z0-9_\.\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]+)(?=\s|$)/g
6264

6365
export interface MentionSuggestion {
6466
type: "file" | "folder" | "git" | "problems"

0 commit comments

Comments
 (0)