F1: settings.set refuses quoted, padded and control-character paths
Path settings get Kind::Path, checked by check_path in the engine: the one validator for settings.set from agents, the CLI and the dialog. settings.list marks them with path: true; the dialog uses that flag for Browse and shows the engine's reason (userMessage drops the invalid-params prefix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
750ecf5e51
commit
8a05f508c8
8 changed files with 150 additions and 51 deletions
|
|
@ -361,13 +361,13 @@ describe("settings dialog", () => {
|
|||
expect((input().element as HTMLInputElement).value).toBe("20");
|
||||
});
|
||||
|
||||
it("shows the engine's error for a value it refuses", async () => {
|
||||
it("shows the engine's error for a value it refuses, without the key the row already names", async () => {
|
||||
const wrapper = await mountDialog();
|
||||
await open(wrapper);
|
||||
await useSettingsStore(pinia).set("editor.fontSize", 2);
|
||||
await wrapper.find("[data-section=editor]").trigger("click");
|
||||
expect(row(wrapper, "editor.fontSize").find("[data-test=settings-error]").text()).toBe(
|
||||
"editor.fontSize: expected an integer from 8 to 48",
|
||||
"expected an integer from 8 to 48",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ function stringEntry(key: string, section: string): Record<string, unknown> {
|
|||
labelKey: `settings.${key}.label`,
|
||||
descriptionKey: `settings.${key}.description`,
|
||||
section,
|
||||
path: /(path|executable)$/i.test(key),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -159,6 +160,10 @@ beforeEach(() => {
|
|||
return Promise.resolve({ values: Object.fromEntries(keys.map((k) => [k, values[k]])) });
|
||||
}
|
||||
case "settings.set":
|
||||
if (typeof params.value === "string" && params.value.startsWith('"')) {
|
||||
const message = `invalid params for settings.set: ${String(params.key)}: Remove the quotes around the path`;
|
||||
return Promise.reject(Object.assign(new Error("x"), { code: "invalid_params", message }));
|
||||
}
|
||||
if (params.value === "/does/not/exist") {
|
||||
return Promise.reject(Object.assign(new Error("x"), { code: "invalid_params", message: "no such file" }));
|
||||
}
|
||||
|
|
@ -182,12 +187,13 @@ afterEach(() => {
|
|||
});
|
||||
|
||||
describe("string setting rules", () => {
|
||||
it("treats keys ending in path or executable as paths", () => {
|
||||
it("treats the settings the engine marks as paths as paths", () => {
|
||||
expect(isPathSetting(defOf("php.executable"))).toBe(true);
|
||||
expect(isPathSetting(defOf("phpactor.path"))).toBe(true);
|
||||
expect(isPathSetting(defOf("git.executable"))).toBe(true);
|
||||
expect(isPathSetting(defOf("x.pharPath"))).toBe(true);
|
||||
expect(isPathSetting(defOf("editor.name"))).toBe(false);
|
||||
expect(isPathSetting({ ...defOf("php.executable"), path: false })).toBe(false);
|
||||
expect(isPathSetting({ ...defOf("php.executable"), type: "int" })).toBe(false);
|
||||
});
|
||||
|
||||
|
|
@ -197,16 +203,16 @@ describe("string setting rules", () => {
|
|||
expect(placeholderOf(defOf("editor.name"))).toBe("");
|
||||
});
|
||||
|
||||
it("refuses long texts, control characters, quoted and padded paths", () => {
|
||||
it("refuses long texts and control characters, and leaves paths to the engine", () => {
|
||||
const php = defOf("php.executable");
|
||||
const name = defOf("editor.name");
|
||||
expect(checkString(php, "C:\\php\\php.exe")).toBeNull();
|
||||
expect(checkString(php, "")).toBeNull();
|
||||
expect(checkString(php, "/opt/my php/php")).toBeNull();
|
||||
expect(checkString(php, '"C:\\Program Files\\php\\php.exe"')).toBe("Remove the quotes around the path");
|
||||
expect(checkString(php, "'/opt/php'")).toBe("Remove the quotes around the path");
|
||||
expect(checkString(php, " /opt/php")).toBe("Remove the spaces at the start or end of the path");
|
||||
expect(checkString(php, "/opt/php\t")).toBe("Remove tabs, line breaks and other control characters");
|
||||
expect(checkString(php, '"C:\\Program Files\\php\\php.exe"')).toBeNull();
|
||||
expect(checkString(php, "'/opt/php'")).toBeNull();
|
||||
expect(checkString(php, " /opt/php")).toBeNull();
|
||||
expect(checkString(php, "/opt/php\t")).toBeNull();
|
||||
expect(checkString(name, " padded is fine ")).toBeNull();
|
||||
expect(checkString(name, "ä".repeat(MAX_STRING_BYTES / 2))).toBeNull();
|
||||
expect(checkString(name, "ä".repeat(MAX_STRING_BYTES / 2 + 1))).toBe(`Enter at most ${String(MAX_STRING_BYTES)} bytes`);
|
||||
|
|
@ -238,16 +244,16 @@ describe("string and path controls", () => {
|
|||
expect(row(wrapper, "php.executable").find("[data-test=settings-error]").exists()).toBe(false);
|
||||
});
|
||||
|
||||
it("refuses a quoted path in place and keeps the typed text", async () => {
|
||||
it("shows the engine's refusal of a quoted path in place and keeps the typed text", async () => {
|
||||
const wrapper = await openDialog();
|
||||
await commit(wrapper, "php.executable", '"C:\\php\\php.exe"');
|
||||
expect(sets()).toEqual([]);
|
||||
expect(sets()).toEqual([{ key: "php.executable", value: '"C:\\php\\php.exe"' }]);
|
||||
const php = row(wrapper, "php.executable");
|
||||
expect(php.find("[data-test=settings-error]").text()).toBe("Remove the quotes around the path");
|
||||
expect(php.find("input").attributes("aria-invalid")).toBe("true");
|
||||
expect((php.find("input").element as HTMLInputElement).value).toBe('"C:\\php\\php.exe"');
|
||||
await commit(wrapper, "php.executable", "C:\\php\\php.exe");
|
||||
expect(sets()).toEqual([{ key: "php.executable", value: "C:\\php\\php.exe" }]);
|
||||
expect(sets().at(-1)).toEqual({ key: "php.executable", value: "C:\\php\\php.exe" });
|
||||
expect(php.find("[data-test=settings-error]").exists()).toBe(false);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue