Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ export function convertDebuggerPathToClient(
// normalize slashes for windows-to-unix
const serverRelative = (serverIsWindows ? path.win32 : path.posix).relative(mappedServerPath, serverPath)
if (serverRelative.indexOf('..') !== 0) {
serverSourceRoot = mappedServerPath
localSourceRoot = mappedLocalSource
break
// If a matching mapping has previously been found, only update
// it if the current server path is longer than the previous one
// (longest prefix matching)
if (!serverSourceRoot || mappedServerPath.length > serverSourceRoot.length) {
serverSourceRoot = mappedServerPath
localSourceRoot = mappedLocalSource
}
}
}
}
Expand Down Expand Up @@ -82,9 +86,13 @@ export function convertClientPathToDebugger(localPath: string, pathMapping?: { [
const mappedLocalSource = pathMapping[mappedServerPath]
const localRelative = path.relative(mappedLocalSource, localPath)
if (localRelative.indexOf('..') !== 0) {
serverSourceRoot = mappedServerPath
localSourceRoot = mappedLocalSource
break
// If a matching mapping has previously been found, only update
// it if the current local path is longer than the previous one
// (longest prefix matching)
if (!localSourceRoot || mappedLocalSource.length > localSourceRoot.length) {
serverSourceRoot = mappedServerPath
localSourceRoot = mappedLocalSource
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ describe('paths', () => {
}),
'file:///app/source.php'
)
// longest prefix matching for server paths
assert.strictEqual(
convertClientPathToDebugger('/home/felix/mysource/subdir/source.php', {
'/var/www': '/home/felix/mysite',
'/app/subdir1': '/home/felix/mysource/subdir',
Comment thread
bjoluc marked this conversation as resolved.
'/app': '/home/felix/mysource',
}),
'file:///app/subdir1/source.php'
)
})
// unix to windows
it('should convert a unix path to a windows URI', () => {
Expand Down Expand Up @@ -165,6 +174,15 @@ describe('paths', () => {
}),
'/home/felix/mysource/source.php'
)
// longest prefix matching for local paths
assert.strictEqual(
convertDebuggerPathToClient('file:///app/subdir/source.php', {
'/var/www': '/home/felix/mysite',
'/app/subdir': '/home/felix/mysource/subdir1',
Comment thread
bjoluc marked this conversation as resolved.
'/app': '/home/felix/mysource',
}),
'/home/felix/mysource/subdir1/source.php'
)
})
// unix to windows
;(process.platform === 'win32' ? it : it.skip)('should map unix uris to windows paths', () => {
Expand Down