From ac1ce697a5ca4ad0b2963cbe331b1421c265e5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bertron?= Date: Thu, 4 Mar 2021 13:54:20 +0100 Subject: [PATCH 1/2] fix: residual space after section causes bad parsing Any character left on a line after a section should be ignored. --- 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 d05682b..2df17e8 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -67,8 +67,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 = /^\[([^\]]*)\].*$|^([^=]+)(=(.*))?$/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 20e521b..1cccaa0 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 22b72b6..1bb7e8b 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] From 6949c304e88d2879cdcb726b53ab01cc92bc65f1 Mon Sep 17 00:00:00 2001 From: Gar Date: Tue, 11 Apr 2023 18:43:21 -0700 Subject: [PATCH 2/2] fixup! fix: residual space after section causes bad parsing --- lib/ini.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index 2df17e8..a6112c1 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -67,8 +67,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) {