diff --git a/packages/ctl/src/config_ops.ts b/packages/ctl/src/config_ops.ts index bf0e8a4b..09299657 100644 --- a/packages/ctl/src/config_ops.ts +++ b/packages/ctl/src/config_ops.ts @@ -16,7 +16,7 @@ export async function configToKeyVal(data: string) { for (let index in filtered) { if (index in filtered) { let split = filtered[index].split("="); - let finalIndex = filtered[index][0].trim(); + let finalIndex = split[0].trim(); // split on the = we added earlier, giving us both value and key let part = ""; try { diff --git a/test/ctl/config_ops.test.js b/test/ctl/config_ops.test.js new file mode 100644 index 00000000..5d3921e1 --- /dev/null +++ b/test/ctl/config_ops.test.js @@ -0,0 +1,21 @@ +import assert from "node:assert/strict"; +import { configToKeyVal } from "@clusterio/ctl/dist/node/src/config_ops.js"; + +describe("ctl/config_ops", function() { + it("preserves full field names with LF and CRLF input", async function() { + for (let newline of ["\n", "\r\n"]) { + const data = [ + "# Clusterio configuration", + "", + "instance.name = Example", + "inventory_sync.load_plugin = false", + "", + ].join(newline); + + assert.deepEqual(await configToKeyVal(data), { + "instance.name": "Example", + "inventory_sync.load_plugin": "false", + }); + } + }); +});