Skip to content

Commit b4a0706

Browse files
authored
Merge pull request #125 from codacy/handle-quotes-CF-1754
fix: Handle path name on windows with quotes CF-1754
2 parents d47d19c + ba38779 commit b4a0706

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/cli/WinWSLCodacyCli.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import { MacCodacyCli } from './MacCodacyCli'
22

33
export class WinWSLCodacyCli extends MacCodacyCli {
44
constructor(rootPath: string, provider?: string, organization?: string, repository?: string) {
5-
const winRootPath = rootPath.startsWith('/mnt/') ? WinWSLCodacyCli.fromWSLPath(rootPath) : rootPath
5+
const winRootPath =
6+
rootPath.startsWith('/mnt/') || rootPath.startsWith("'/mnt/") ? WinWSLCodacyCli.fromWSLPath(rootPath) : rootPath
67
super(winRootPath, provider, organization, repository)
78
}
89

910
private static toWSLPath(path: string): string {
1011
// Convert Windows path to WSL path
11-
// Example: C:\Users\user\project -> /mnt/c/Users/user/project
12-
const wslPath = path.replace(/\\/g, '/').replace(/^([a-zA-Z]):/, '/mnt/$1')
12+
// Example: 'C:\Users\user\project' -> '/mnt/c/Users/user/project'
13+
const wslPath = path.replace(/\\/g, '/').replace(/^'([a-zA-Z]):/, "'/mnt/$1")
1314
return wslPath
1415
}
1516

1617
private static fromWSLPath(path: string): string {
17-
// Convert WSL path to Windows path
18-
// Example: /mnt/c/Users/user/project -> C:\Users\user\project
19-
const windowsPath = path.replace(/^\/mnt\/([a-zA-Z])/, '$1:').replace(/\//g, '\\')
18+
// Convert WSL path to Windows path while keeping quotes
19+
// Example: '/mnt/c/Users/user/project' -> 'C:\Users\user\project'
20+
const windowsPath = path.replace(/^'\/mnt\/([a-zA-Z])/, "'$1:").replace(/\//g, '\\')
2021
return windowsPath
2122
}
2223

0 commit comments

Comments
 (0)