|
1 | | -import urlRelative = require('url-relative') |
2 | 1 | import fileUrl = require('file-url') |
3 | 2 | import * as url from 'url' |
4 | 3 | import * as path from 'path' |
5 | 4 | import { decode } from 'urlencode' |
| 5 | +import RelateUrl from 'relateurl' |
| 6 | + |
| 7 | +/** |
| 8 | + * Options to make sure that RelateUrl only outputs relative URLs and performs not other "smart" modifications. |
| 9 | + * They would mess up things like prefix checking. |
| 10 | + */ |
| 11 | +const RELATE_URL_OPTIONS: RelateUrl.Options = { |
| 12 | + // Make sure RelateUrl does not prefer root-relative URLs if shorter |
| 13 | + output: RelateUrl.PATH_RELATIVE, |
| 14 | + // Make sure RelateUrl does not remove trailing slash if present |
| 15 | + removeRootTrailingSlash: false, |
| 16 | + // Make sure RelateUrl does not remove default ports |
| 17 | + defaultPorts: {}, |
| 18 | +} |
| 19 | + |
| 20 | +/** |
| 21 | + * Like `path.relative()` but for URLs. |
| 22 | + * Inverse of `url.resolve()` or `new URL(relative, base)`. |
| 23 | + */ |
| 24 | +const relativeUrl = (from: string, to: string): string => RelateUrl.relate(from, to, RELATE_URL_OPTIONS) |
6 | 25 |
|
7 | 26 | /** converts a server-side XDebug file URI to a local path for VS Code with respect to source root settings */ |
8 | 27 | export function convertDebuggerPathToClient( |
@@ -85,7 +104,7 @@ export function convertClientPathToDebugger(localPath: string, pathMapping?: { [ |
85 | 104 | serverSourceRootUrl += '/' |
86 | 105 | } |
87 | 106 | // get the part of the path that is relative to the source root |
88 | | - const urlRelativeToSourceRoot = urlRelative(localSourceRootUrl, localFileUri) |
| 107 | + const urlRelativeToSourceRoot = relativeUrl(localSourceRootUrl, localFileUri) |
89 | 108 | // resolve from the server source root |
90 | 109 | serverFileUri = url.resolve(serverSourceRootUrl, urlRelativeToSourceRoot) |
91 | 110 | } else { |
|
0 commit comments