Skip to content

Commit f2a0dce

Browse files
authored
fix: Detect IDE path format for convertDebuggerPathToClient (#525)
1 parent d7021db commit f2a0dce

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/paths.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ export function convertDebuggerPathToClient(
5858
}
5959
let localPath: string
6060
if (serverSourceRoot && localSourceRoot) {
61+
const clientIsWindows = /^[a-zA-Z]:\\/.test(localSourceRoot) || /^\\\\/.test(localSourceRoot)
6162
// get the part of the path that is relative to the source root
62-
const pathRelativeToSourceRoot = (serverIsWindows ? path.win32 : path.posix).relative(
63+
let pathRelativeToSourceRoot = (serverIsWindows ? path.win32 : path.posix).relative(
6364
serverSourceRoot,
6465
serverPath
6566
)
67+
if (serverIsWindows && !clientIsWindows) {
68+
pathRelativeToSourceRoot = pathRelativeToSourceRoot.replace(/\\/g, path.posix.sep)
69+
}
6670
// resolve from the local source root
67-
localPath = path.resolve(localSourceRoot, pathRelativeToSourceRoot)
71+
localPath = (clientIsWindows ? path.win32 : path.posix).resolve(localSourceRoot, pathRelativeToSourceRoot)
6872
} else {
69-
localPath = path.normalize(serverPath)
73+
localPath = (serverIsWindows ? path.win32 : path.posix).normalize(serverPath)
7074
}
7175
return localPath
7276
}

src/test/paths.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ describe('paths', () => {
139139
})
140140
describe('convertDebuggerPathToClient', () => {
141141
describe('without source mapping', () => {
142-
;(process.platform === 'win32' ? it : it.skip)('should convert a windows URI to a windows path', () => {
142+
it('should convert a windows URI to a windows path', () => {
143143
assert.equal(
144144
convertDebuggerPathToClient('file:///C:/Users/felix/test.php'),
145145
'C:\\Users\\felix\\test.php'
146146
)
147147
})
148-
;(process.platform !== 'win32' ? it : it.skip)('should convert a unix URI to a unix path', () => {
148+
it('should convert a unix URI to a unix path', () => {
149149
assert.equal(convertDebuggerPathToClient('file:///home/felix/test.php'), '/home/felix/test.php')
150150
})
151-
;(process.platform === 'win32' ? it : it.skip)('should handle non-unicode special characters', () => {
151+
it('should handle non-unicode special characters', () => {
152152
assert.equal(
153153
convertDebuggerPathToClient('file:///d:/arx%20iT/2-R%C3%A9alisation/mmi/V1.0/Web/core/header.php'),
154154
'd:\\arx iT\\2-Réalisation\\mmi\\V1.0\\Web\\core\\header.php'
@@ -157,7 +157,7 @@ describe('paths', () => {
157157
})
158158
describe('with source mapping', () => {
159159
// unix to unix
160-
;(process.platform !== 'win32' ? it : it.skip)('should map unix uris to unix paths', () => {
160+
it('should map unix uris to unix paths', () => {
161161
// site
162162
assert.equal(
163163
convertDebuggerPathToClient('file:///var/www/site.php', {
@@ -185,7 +185,7 @@ describe('paths', () => {
185185
)
186186
})
187187
// unix to windows
188-
;(process.platform === 'win32' ? it : it.skip)('should map unix uris to windows paths', () => {
188+
it('should map unix uris to windows paths', () => {
189189
// site
190190
assert.equal(
191191
convertDebuggerPathToClient('file:///var/www/site.php', {
@@ -204,7 +204,7 @@ describe('paths', () => {
204204
)
205205
})
206206
// windows to unix
207-
;(process.platform !== 'win32' ? it : it.skip)('should map windows uris to unix paths', () => {
207+
it('should map windows uris to unix paths', () => {
208208
// site
209209
assert.equal(
210210
convertDebuggerPathToClient('file:///C:/Program%20Files/Apache/2.4/htdocs/site.php', {
@@ -221,9 +221,17 @@ describe('paths', () => {
221221
}),
222222
'/home/felix/mysource/source.php'
223223
)
224+
// multi level source
225+
assert.equal(
226+
convertDebuggerPathToClient('file:///C:/Program%20Files/MySource/src/app/source.php', {
227+
'C:\\Program Files\\Apache\\2.4\\htdocs': '/home/felix/mysite',
228+
'C:\\Program Files\\MySource': '/home/felix/mysource',
229+
}),
230+
'/home/felix/mysource/src/app/source.php'
231+
)
224232
})
225233
// windows to windows
226-
;(process.platform === 'win32' ? it : it.skip)('should map windows uris to windows paths', () => {
234+
it('should map windows uris to windows paths', () => {
227235
// site
228236
assert.equal(
229237
convertDebuggerPathToClient('file:///C:/Program%20Files/Apache/2.4/htdocs/site.php', {

0 commit comments

Comments
 (0)