Config UI: trim string values (#20169)

This commit is contained in:
Michael Geers 2025-03-27 15:50:30 +01:00 • committed by GitHub
parent ee157ee447
commit b649f07287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -125,7 +125,8 @@ export default {
this.saving = true;
this.error = "";
try {
const res = await api[this.saveMethod](this.endpoint, this.values, {
const values = this.trimValues(this.values);
const res = await api[this.saveMethod](this.endpoint, values, {
validateStatus: (code) => [200, 202, 400].includes(code),
});
if (res.status === 200 || res.status === 202) {
@ -159,6 +160,15 @@ export default {
}
this.removing = false;
},
trimValues(values) {
// extend to recursive when needed in the future
return Object.fromEntries(
Object.entries(values).map(([key, value]) => [
key,
typeof value === "string" ? value.trim() : value,
])
);
},
},
};
</script>

View file

@ -27,7 +27,7 @@ test.describe("mqtt", async () => {
const modal = await page.getByTestId("mqtt-modal");
await modal.getByLabel("Broker").fill("unknown.example.org");
await modal.getByLabel("Topic").fill("my-topic");
await modal.getByLabel("Topic").fill(" my-topic "); // whitespace should be trimmed
await modal.getByLabel("Client ID").fill("my-client-id");
await page.getByRole("button", { name: "Save" }).click();