taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 03c36d57c23f6d21bbfbe46910577a2960035761
parent 74de25129b1f7e219e7277596eba67d258f838dc
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 20:01:39 +0200

util: test config write-back

Diffstat:
Mpackages/taler-util/src/talerconfig.test.ts | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/packages/taler-util/src/talerconfig.test.ts b/packages/taler-util/src/talerconfig.test.ts @@ -356,3 +356,41 @@ test("@inline-secret@ still requires two arguments", (t) => { /requires two arguments/, ); }); + +test("write-back escapes newlines in values", (t) => { + // configuration.c rewrites an embedded newline to a backslash-n before + // writing, otherwise a value carrying one emits extra configuration lines. + const config = new Configuration(); + config.setString("exchange", "base_url", "https://real/\n[evil]\nX = y"); + const out = config.stringify(); + assert.ok(!/\n\[evil\]/.test(out), `injected a section: ${out}`); + assert.strictEqual( + out, + "[exchange]\nbase_url = https://real/\\n[evil]\\nX = y\n\n", + ); +}); + +test("write-back preserves values with significant whitespace", (t) => { + // A value only keeps its leading or trailing spaces if it is quoted, and + // the reader strips the quotes again. + const config = new Configuration(); + config.setString("exchange", "padded", " spaced "); + const reloaded = new Configuration(); + reloaded.loadFromString(config.stringify()); + assert.strictEqual( + reloaded.getString("exchange", "padded").required(), + " spaced ", + ); +}); + +test("write-back preserves the spelling of section and option names", (t) => { + // write() overwrites the user's own file, so it must not rewrite + // [exchange]/base_url as [EXCHANGE]/BASE_URL. The C keeps the name as it + // was first seen. + const config = new Configuration(); + config.loadFromString("[exchange]\nbase_url = https://real/\n"); + assert.strictEqual( + config.stringify(), + "[exchange]\nbase_url = https://real/\n\n", + ); +});