mirror of
https://github.com/coder/code-server.git
synced 2026-10-25 09:51:48 +08:00
Expand ~ in path options from the config file (#8055)
The shell expands ~ in command-line arguments, but values read from config.yaml were passed to path.resolve as-is, so `user-data-dir: ~/.config/code-server-data` resolved to `<cwd>/~/.config/code-server-data`.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Level, logger } from "@coder/logger"
|
||||
import { promises as fs } from "fs"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
import {
|
||||
UserProvidedArgs,
|
||||
@@ -575,6 +576,17 @@ describe("parser", () => {
|
||||
"install-extension": ["extension.number1", "extension.number2"],
|
||||
})
|
||||
})
|
||||
it("should expand ~ in path options from the config file", () => {
|
||||
const configContents = `
|
||||
user-data-dir: ~/.config/code-server-data
|
||||
extensions-dir: ~/extensions
|
||||
`
|
||||
expect(parseConfigFile(configContents, "/fake-config-path")).toEqual({
|
||||
config: "/fake-config-path",
|
||||
"user-data-dir": path.join(os.homedir(), ".config/code-server-data"),
|
||||
"extensions-dir": path.join(os.homedir(), "extensions"),
|
||||
})
|
||||
})
|
||||
it("should ignore optional strings set to false", async () => {
|
||||
expect(parse(["--cert=false"])).toEqual({})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as cp from "child_process"
|
||||
import { promises as fs } from "fs"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
import { generateUuid } from "../../../src/common/util"
|
||||
import { tmpdir } from "../../../src/node/constants"
|
||||
@@ -623,3 +624,18 @@ describe("splitOnFirstEquals", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("expandTilde", () => {
|
||||
it("should expand a bare ~", () => {
|
||||
expect(util.expandTilde("~")).toBe(os.homedir())
|
||||
})
|
||||
it("should expand a leading ~/", () => {
|
||||
expect(util.expandTilde("~/.config/code-server")).toBe(path.join(os.homedir(), ".config/code-server"))
|
||||
})
|
||||
it("should leave other paths alone", () => {
|
||||
expect(util.expandTilde("/tmp/~/data")).toBe("/tmp/~/data")
|
||||
expect(util.expandTilde("relative/~")).toBe("relative/~")
|
||||
expect(util.expandTilde("~user/data")).toBe("~user/data")
|
||||
expect(util.expandTilde("")).toBe("")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user