Skip to content

Commit 2329c58

Browse files
committed
Add support for paths starting with a slash in path extraction
- make sure such incoming path: `/src/hello.ts` matches workspace's `src/hello.ts`
1 parent ad1206a commit 2329c58

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎apps/editor/src/utils/extract-paths-from-text/extract-paths-from-text.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,12 @@ Lorem ipsum.`
8484
'apps/editor/src/features/checkpoints/actions/restore-checkpoint.ts'
8585
)
8686
})
87+
88+
it('extracts paths starting with a slash', () => {
89+
const text = 'Look at /src/hello.ts'
90+
const workspace_files = ['src/hello.ts']
91+
const result = extract_paths_from_text({ text, workspace_files })
92+
93+
expect(result).toContain('src/hello.ts')
94+
})
8795
})

‎apps/editor/src/utils/extract-paths-from-text/extract-paths-from-text.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const extract_paths_from_text = (params: {
4040
let p = original_p
4141
if (p.startsWith('./')) {
4242
p = p.substring(2)
43+
} else if (p.startsWith('/')) {
44+
p = p.substring(1)
4345
}
4446

4547
if (!p) continue

0 commit comments

Comments
 (0)