From 5b5c9b777209bae480f62fb80149008350d37bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bertron?= Date: Wed, 12 Apr 2023 17:27:22 +0200 Subject: [PATCH] fix: residual space after section causes bad parsing (#123) --- lib/ini.js | 4 ++-- tap-snapshots/test/foo.js.test.cjs | 1 + test/fixtures/foo.ini | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index 65ffea9..be5efb6 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -69,8 +69,8 @@ const decode = str => { const out = Object.create(null) let p = out let section = null - // section |key = value - const re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i + // section |key = value + const re = /^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i const lines = str.split(/[\r\n]+/g) for (const line of lines) { diff --git a/tap-snapshots/test/foo.js.test.cjs b/tap-snapshots/test/foo.js.test.cjs index 28feb7a..c80ffdf 100644 --- a/tap-snapshots/test/foo.js.test.cjs +++ b/tap-snapshots/test/foo.js.test.cjs @@ -35,6 +35,7 @@ Null Object { "three", "this is included", ], + "b": Null Object {}, "br": "warm", "eq": "eq=eq", "false": false, diff --git a/test/fixtures/foo.ini b/test/fixtures/foo.ini index 4aee69c..219b4aa 100644 --- a/test/fixtures/foo.ini +++ b/test/fixtures/foo.ini @@ -69,6 +69,9 @@ j = "{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }" cr[] = four cr[] = eight +; b section with a space after its title +[b] + ; nested child without middle parent ; should create otherwise-empty a.b [a.b.c]