fix: handle formatter paths relative to workspace

This commit is contained in:
chen zhihao
2026-09-01 10:58:12 +08:00
parent de096ff4a8
commit 5062505330
+9 -1
View File
@@ -46,7 +46,15 @@ export function normalizeURL(url: string): string {
export function getStoragePath(filepath: string, rootDir: string): string {
const root = path.resolve(rootDir)
const target = path.resolve(path.isAbsolute(filepath) ? filepath : path.join(root, filepath))
const candidate = path.resolve(filepath)
const candidateRelative = path.relative(root, candidate)
const target =
path.isAbsolute(filepath) ||
(candidateRelative !== '..' &&
!candidateRelative.startsWith(`..${path.sep}`) &&
!path.isAbsolute(candidateRelative))
? candidate
: path.resolve(root, filepath)
const relative = path.relative(root, target)
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {