Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ const decode = (str, opt = {}) => {
if (part === '__proto__') {
continue
}
if (!hasOwnProperty.call(p, part) || typeof p[part] !== 'object') {
// 2026-10-11: Null is a scalar value, so it cannot contain a nested section.
if (!hasOwnProperty.call(p, part) || p[part] === null || typeof p[part] !== 'object') {
p[part] = Object.create(null)
}
p = p[part]
Expand Down
22 changes: 22 additions & 0 deletions test/null-sections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ini = require('../')
const t = require('tap')

// 2026-10-11: Section paths replace null ancestors just like other scalar values.
t.test('nested sections replace scalar parents', t => {
for (const value of ['null', 'false', 'text']) {
t.test(`replace a ${value} parent`, t => {
t.same(ini.parse(`a=${value}\n[a.b]\nx=1`), {
a: { b: { x: '1' } },
})
t.end()
})
}
t.same(ini.parse('[a]\nb=null\n[a.b.c]\nx=1'), {
a: { b: { c: { x: '1' } } },
}, 'replace a null parent inside a section')
t.same(ini.parse('a.b=null\n[a.b.c]\nx=1'), {
a: { b: { c: { x: '1' } } },
}, 'replace a null parent introduced by a dotted key')
t.same(ini.parse('a=null'), { a: null }, 'retain null without a nested section')
t.end()
})