From 858cc82dff7eac9ff9a56181132d66d0e09a803c Mon Sep 17 00:00:00 2001 From: James Ross Date: Wed, 22 May 2024 16:50:58 +0100 Subject: [PATCH] fix: decoding bracketed arrays (#252) --- lib/ini.js | 4 +++- tap-snapshots/test/duplicate-properties.js.test.cjs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index 0e8623e..beb390d 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -140,7 +140,9 @@ const decode = (str, opt = {}) => { duplicates[keyRaw] = (duplicates?.[keyRaw] || 0) + 1 isArray = duplicates[keyRaw] > 1 } - const key = isArray ? keyRaw.slice(0, -2) : keyRaw + const key = isArray && keyRaw.endsWith('[]') + ? keyRaw.slice(0, -2) : keyRaw + if (key === '__proto__') { continue } diff --git a/tap-snapshots/test/duplicate-properties.js.test.cjs b/tap-snapshots/test/duplicate-properties.js.test.cjs index 4a88d10..7feb707 100644 --- a/tap-snapshots/test/duplicate-properties.js.test.cjs +++ b/tap-snapshots/test/duplicate-properties.js.test.cjs @@ -11,12 +11,12 @@ Null Object { "three", ], "ar[]": "one", - "b": Array [ + "brr": Array [ + "1", "2", "3", "3", ], - "brr": "1", "str": "3", "zr": "123", "zr[]": "deedee",