commit 3ddab3227044d1b39c3a4cd85a946cb408aca1a2
parent cea0d5c2d7c607cecabdc42d353c2353340bb34b
Author: Florian Dold <dold@taler.net>
Date: Tue, 21 Jul 2026 12:35:47 +0200
util: test config line normalization against the C implementation
Diffstat:
1 file changed, 47 insertions(+), 0 deletions(-)
diff --git a/packages/taler-util/src/talerconfig.test.ts b/packages/taler-util/src/talerconfig.test.ts
@@ -122,3 +122,50 @@ test("recursive path resolution", (t) => {
config.getPath("foo", "a").required();
});
});
+
+test("a config file with CRLF line endings loads", (t) => {
+ // GNUnet rewrites tabs and carriage returns to spaces before classifying a
+ // line, so a file the C tools load must load here too.
+ const config = new Configuration();
+ config.loadFromString(
+ ["# a comment", "[exchange]", "BASE_URL = https://real/", ""].join("\r\n"),
+ );
+ assert.strictEqual(
+ config.getString("exchange", "base_url").required(),
+ "https://real/",
+ );
+});
+
+test("a commented-out option stays a comment with CRLF line endings", (t) => {
+ // A comment containing an '=' must not be parsed as an assignment, which is
+ // what happens when the comment pattern fails to match and the parameter
+ // pattern is tried next.
+ const config = new Configuration();
+ config.loadFromString(
+ [
+ "[exchange]",
+ "BASE_URL = https://real/",
+ "# BASE_URL = https://old/",
+ "",
+ ].join("\r\n"),
+ );
+ assert.strictEqual(
+ config.getString("exchange", "base_url").required(),
+ "https://real/",
+ );
+ assert.strictEqual(
+ config.stringify(),
+ "[EXCHANGE]\nBASE_URL = https://real/\n\n",
+ );
+});
+
+test("tabs are whitespace, as in the C implementation", (t) => {
+ const config = new Configuration();
+ config.loadFromString("\t# a comment\n[exchange]\n\tBASE_URL\t=\tfoo\tbar\n");
+ // configuration.c rewrites every tab to a space before parsing the line,
+ // so one inside a value is stored as a space.
+ assert.strictEqual(
+ config.getString("exchange", "base_url").required(),
+ "foo bar",
+ );
+});