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
6 changes: 4 additions & 2 deletions lib/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const encode = (obj, opt = {}) => {
} else if (val && typeof val === 'object') {
children.push(k)
} else {
out += safe(k).padEnd(padToChars, ' ') + separator + safe(val) + eol
const safeKey = opt.bracketedArray && k.endsWith('[]') ? JSON.stringify(k) : safe(k)
out += safeKey.padEnd(padToChars, ' ') + separator + safe(val) + eol
}
}

Expand Down Expand Up @@ -135,7 +136,8 @@ const decode = (str, opt = {}) => {
const keyRaw = unsafe(match[2])
let isArray
if (opt.bracketedArray) {
isArray = keyRaw.length > 2 && keyRaw.slice(-2) === '[]'
const rawKey = match[2].trim()
isArray = !isQuoted(rawKey) && rawKey.length > 2 && rawKey.slice(-2) === '[]'
} else {
duplicates[keyRaw] = (duplicates?.[keyRaw] || 0) + 1
isArray = duplicates[keyRaw] > 1
Expand Down
1 change: 1 addition & 0 deletions test/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var data = {
string: { drink: 'white russian' },
boolean: { isTrue: true },
'nested boolean': { theDude: { abides: true, rugCount: 1 } },
'key ending in []': { 'foo[]': 'bar' },
}

test('parse(stringify(x)) is same as x', function (t) {
Expand Down