refactor: only accept string in pathToFsPath
CodeQL caught a path where we were passing in req.query.path to pathToFsPath, which may not have been a string. So we refactored some things to ensure we only pass it a string which also let us change the parameter type to string instead of string | string[].
This commit is contained in:
@ -458,17 +458,11 @@ enum CharCode {
|
||||
* Taken from vs/base/common/uri.ts. It's not imported to avoid also importing
|
||||
* everything that file imports.
|
||||
*/
|
||||
export function pathToFsPath(path: string | string[], keepDriveLetterCasing = false): string {
|
||||
export function pathToFsPath(path: string, keepDriveLetterCasing = false): string {
|
||||
const isWindows = process.platform === "win32"
|
||||
const uri = { authority: undefined, path: getFirstString(path), scheme: "file" }
|
||||
const uri = { authority: undefined, path: getFirstString(path) || "", scheme: "file" }
|
||||
let value: string
|
||||
|
||||
if (typeof uri.path !== "string") {
|
||||
throw new Error(
|
||||
`Could not compute fsPath from given uri. Expected path to be of type string, but was of type ${typeof uri.path}.`,
|
||||
)
|
||||
}
|
||||
|
||||
if (uri.authority && uri.path.length > 1 && uri.scheme === "file") {
|
||||
// unc path: file://shares/c$/far/boo
|
||||
value = `//${uri.authority}${uri.path}`
|
||||
|
Reference in New Issue
Block a user