| author | |
| committer | |
| log | c6410d37d7ff1bdb65b38f0e9c30da392a4de804 |
| tree | 91326c0f05ae82cf6eabc24b2cb4ba3fea9a05de |
| parent | aca2afc0b5400e4cf88c42d59b214240833ed9cd |
| signature | Signed by PGP key B5690EEEBB952194 |
2 files changed, 1 insertions(+), 24 deletions(-)
packages/shared/src/composerTrigger.test.ts+1-15| ... | @@ -1,20 +1,6 @@ | ... | @@ -1,20 +1,6 @@ |
| 1 | import { describe, expect, it } from "vite-plus/test"; | 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | 2 | ||
| 3 | import { serializeComposerFileLink, serializeComposerMentionPath } from "./composerTrigger.ts"; | 3 | import { serializeComposerFileLink } from "./composerTrigger.ts"; |
| 4 | |||
| 5 | describe("serializeComposerMentionPath", () => { | ||
| 6 | it("keeps simple mention paths unquoted", () => { | ||
| 7 | expect(serializeComposerMentionPath("src/index.ts")).toBe("src/index.ts"); | ||
| 8 | }); | ||
| 9 | |||
| 10 | it("quotes mention paths containing whitespace", () => { | ||
| 11 | expect(serializeComposerMentionPath("docs/My File.md")).toBe('"docs/My File.md"'); | ||
| 12 | }); | ||
| 13 | |||
| 14 | it("escapes quoted mention path content", () => { | ||
| 15 | expect(serializeComposerMentionPath('docs/My "File".md')).toBe('"docs/My \\"File\\".md"'); | ||
| 16 | }); | ||
| 17 | }); | ||
| 18 | 4 | ||
| 19 | describe("serializeComposerFileLink", () => { | 5 | describe("serializeComposerFileLink", () => { |
| 20 | it("uses the basename as the markdown label", () => { | 6 | it("uses the basename as the markdown label", () => { |
packages/shared/src/composerTrigger.ts-9| ... | @@ -8,15 +8,6 @@ export interface ComposerTrigger { | ... | @@ -8,15 +8,6 @@ export interface ComposerTrigger { |
| 8 | rangeEnd: number; | 8 | rangeEnd: number; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | const SIMPLE_MENTION_PATH_REGEX = /^[^\s@"\\]+$/; | ||
| 12 | |||
| 13 | export function serializeComposerMentionPath(path: string): string { | ||
| 14 | if (SIMPLE_MENTION_PATH_REGEX.test(path)) { | ||
| 15 | return path; | ||
| 16 | } | ||
| 17 | return `"${path.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`; | ||
| 18 | } | ||
| 19 | |||
| 20 | function composerFileLinkBasename(path: string): string { | 11 | function composerFileLinkBasename(path: string): string { |
| 21 | const separatorIndex = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")); | 12 | const separatorIndex = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")); |
| 22 | return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path; | 13 | return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path; |