Skip to content

Commit 2617795

Browse files
johnromfelixfbecker
authored andcommitted
fix(paths): lowercase Windows drive letters (#245)
Closes #239
1 parent 68adf04 commit 2617795

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/paths.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export function convertDebuggerPathToClient(
5252
export function convertClientPathToDebugger(localPath: string, pathMapping?: { [index: string]: string }): string {
5353
let localSourceRoot: string | undefined
5454
let serverSourceRoot: string | undefined
55-
let localFileUri = fileUrl(localPath, { resolve: false })
55+
// XDebug always lowercases Windows drive letters in file URIs
56+
let localFileUri = fileUrl(localPath.replace(/^[A-Z]:\\/, match => match.toLowerCase()), { resolve: false })
5657
let serverFileUri: string
5758
if (pathMapping) {
5859
for (const mappedServerPath of Object.keys(pathMapping)) {
@@ -65,6 +66,12 @@ export function convertClientPathToDebugger(localPath: string, pathMapping?: { [
6566
}
6667
}
6768
}
69+
if (localSourceRoot) {
70+
localSourceRoot = localSourceRoot.replace(/^[A-Z]:\\/, match => match.toLowerCase())
71+
}
72+
if (serverSourceRoot) {
73+
serverSourceRoot = serverSourceRoot.replace(/^[A-Z]:\\/, match => match.toLowerCase())
74+
}
6875
if (serverSourceRoot && localSourceRoot) {
6976
let localSourceRootUrl = fileUrl(localSourceRoot, { resolve: false })
7077
if (!localSourceRootUrl.endsWith('/')) {

src/test/paths.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('paths', () => {
2929
it('should convert a windows path to a URI', () => {
3030
assert.equal(
3131
convertClientPathToDebugger('C:\\Users\\felix\\test.php'),
32-
'file:///C:/Users/felix/test.php'
32+
'file:///c:/Users/felix/test.php'
3333
)
3434
})
3535
it('should convert a unix path to a URI', () => {
@@ -64,15 +64,15 @@ describe('paths', () => {
6464
'C:\\Program Files\\Apache\\2.4\\htdocs': '/home/felix/mysite',
6565
'C:\\Program Files\\MySource': '/home/felix/mysource',
6666
}),
67-
'file:///C:/Program%20Files/Apache/2.4/htdocs/site.php'
67+
'file:///c:/Program%20Files/Apache/2.4/htdocs/site.php'
6868
)
6969
// source
7070
assert.equal(
7171
convertClientPathToDebugger('/home/felix/mysource/source.php', {
7272
'C:\\Program Files\\Apache\\2.4\\htdocs': '/home/felix/mysite',
7373
'C:\\Program Files\\MySource': '/home/felix/mysource',
7474
}),
75-
'file:///C:/Program%20Files/MySource/source.php'
75+
'file:///c:/Program%20Files/MySource/source.php'
7676
)
7777
})
7878
// windows to unix
@@ -94,6 +94,19 @@ describe('paths', () => {
9494
'file:///app/source.php'
9595
)
9696
})
97+
;(process.platform === 'win32' ? it : it.skip)(
98+
'should convert a windows path with inconsistent casing to a unix URI',
99+
() => {
100+
const localSourceRoot = 'C:\\Users\\felix\\myproject'
101+
const serverSourceRoot = '/var/www'
102+
assert.equal(
103+
convertClientPathToDebugger('c:\\Users\\felix\\myproject\\test.php', {
104+
[serverSourceRoot]: localSourceRoot,
105+
}),
106+
'file:///var/www/test.php'
107+
)
108+
}
109+
)
97110
// windows to windows
98111
;(process.platform === 'win32' ? it : it.skip)('should convert a windows path to a windows URI', () => {
99112
// site
@@ -102,15 +115,15 @@ describe('paths', () => {
102115
'C:\\Program Files\\Apache\\2.4\\htdocs': 'C:\\Users\\felix\\mysite',
103116
'C:\\Program Files\\MySource': 'C:\\Users\\felix\\mysource',
104117
}),
105-
'file:///C:/Program%20Files/Apache/2.4/htdocs/site.php'
118+
'file:///c:/Program%20Files/Apache/2.4/htdocs/site.php'
106119
)
107120
// source
108121
assert.equal(
109122
convertClientPathToDebugger('C:\\Users\\felix\\mysource\\source.php', {
110123
'C:\\Program Files\\Apache\\2.4\\htdocs': 'C:\\Users\\felix\\mysite',
111124
'C:\\Program Files\\MySource': 'C:\\Users\\felix\\mysource',
112125
}),
113-
'file:///C:/Program%20Files/MySource/source.php'
126+
'file:///c:/Program%20Files/MySource/source.php'
114127
)
115128
})
116129
})

0 commit comments

Comments
 (0)