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 @@ -111,7 +111,8 @@ const decode = (str, opt = {}) => {
// section |key = value
const re = /^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i
const lines = str.split(/[\r\n]+/g)
const duplicates = {}
// 2026-10-11: Count only keys from the input, including prototype member names.
const duplicates = Object.create(null)

for (const line of lines) {
if (!line || line.match(/^\s*[;#]/) || line.match(/^\s*$/)) {
Expand Down
11 changes: 11 additions & 0 deletions test/duplicate-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ test('encode duplicate properties with bracketedArray=false', function (t) {
t.matchSnapshot(e)
t.end()
})

// 2026-10-11: Prototype member names are ordinary duplicate keys in INI data.
test('decode duplicate keys named after prototype properties', function (t) {
for (const key of ['constructor', 'toString', 'valueOf', 'hasOwnProperty']) {
const input = `${key}=first\n${key}=second\n${key}=third`
t.same(i.decode(input, { bracketedArray: false })[key], ['first', 'second', 'third'], key)
t.same(i.decode(`${key}=single`, { bracketedArray: false })[key], 'single', `${key} stays scalar`)
t.same(i.decode(input)[key], 'third', `${key} follows default last-value behavior`)
}
t.end()
})