From cc184bec50446a262164d037a14f3e093c4833a1 Mon Sep 17 00:00:00 2001 From: vhinayindia <281186805+vhinayindia@users.noreply.github.com> Date: Tue, 6 Oct 2026 20:20:16 +0530 Subject: [PATCH] fix: strip inline comments after quoted values --- lib/ini.js | 4 ++++ test/quoted-values.js | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/quoted-values.js diff --git a/lib/ini.js b/lib/ini.js index beb390d..aedb823 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -229,6 +229,10 @@ const safe = val => { const unsafe = val => { val = (val || '').trim() + const quotedValue = val.match(/^("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')\s*[;#]/) + if (quotedValue) { + val = quotedValue[1] + } if (isQuoted(val)) { // remove the single quotes before calling JSON.parse if (val.charAt(0) === "'") { diff --git a/test/quoted-values.js b/test/quoted-values.js new file mode 100644 index 0000000..a2bc4e7 --- /dev/null +++ b/test/quoted-values.js @@ -0,0 +1,10 @@ +const ini = require('../') +const tap = require('tap') + +tap.test('quoted values with inline comments', t => { + t.same(ini.parse('a.b = "c" ; asdf'), { 'a.b': 'c' }) + t.same(ini.parse("value = 'quoted' # comment"), { value: 'quoted' }) + t.same(ini.parse('value = "semi;colon" ; comment'), { value: 'semi;colon' }) + t.same(ini.parse('value = plain ; comment'), { value: 'plain' }) + t.end() +})