From fa57015346d07276532b900961c720202eb6adfc Mon Sep 17 00:00:00 2001 From: amtbsl <147152854+amtbsl@users.noreply.github.com> Date: Sat, 29 Aug 2026 13:36:27 +0800 Subject: [PATCH 1/2] fix: parse comments after quoted values --- lib/ini.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/ini.js b/lib/ini.js index beb390d..2226ef0 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -229,6 +229,31 @@ const safe = val => { const unsafe = val => { val = (val || '').trim() + if (val.charAt(0) === '"' || val.charAt(0) === "'") { + let quote = null + let escaped = false + let commentIndex = -1 + for (let i = 0; i < val.length; i++) { + const c = val.charAt(i) + if (escaped) { + escaped = false + } else if (c === '\\') { + escaped = true + } else if (quote) { + if (c === quote) { + quote = null + } + } else if (c === '"' || c === "'") { + quote = c + } else if (c === ';' || c === '#') { + commentIndex = i + break + } + } + if (commentIndex !== -1) { + val = val.slice(0, commentIndex).trim() + } + } if (isQuoted(val)) { // remove the single quotes before calling JSON.parse if (val.charAt(0) === "'") { From 14796a9eeb89fe2b55b2927a36e67ad99b073a4c Mon Sep 17 00:00:00 2001 From: amtbsl <147152854+amtbsl@users.noreply.github.com> Date: Sat, 29 Aug 2026 13:36:33 +0800 Subject: [PATCH 2/2] test: cover comments after quoted values --- test/foo.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/foo.js b/test/foo.js index fe92435..fa12b30 100644 --- a/test/foo.js +++ b/test/foo.js @@ -14,6 +14,12 @@ test('decode from file', function (t) { t.end() }) +test('decode quoted values before inline comments', function (t) { + const d = i.decode('double = "value" ; comment\nsingle = \'value\' # comment\n') + t.same(d, { double: 'value', single: 'value' }) + t.end() +}) + test('encode from data', function (t) { const d = i.decode(data) const e = i.encode(d)