Is there an existing issue for this?
Current Behavior
When parsing INI content with multiple sections that reuse the same key name:
const content = `
[section_1]
var = 1
[section_2]
var = 2
`
calling:
ini.parse(content, { bracketedArray: false });
returns:
{
Section_1: { var: 1 },
Section_2: { var: [2] }
}
As you can see, Section_2.var is incorrectly returned as an array, even though there is only a single value defined in that section.
I need bracketedArray for legacy compatibility—specifically, to support cases where multiple identical keys within the same section should be parsed as an array.
I believe the issue comes from using a global duplicate counter that is not scoped per section. In ini.js:
duplicates[keyRaw] = (duplicates?.[keyRaw] || 0) + 1;
isArray = duplicates[keyRaw] > 1;
Because duplicates is tracked globally, keys with the same name across different sections are treated as duplicates, which causes later sections to be converted into arrays even when they contain only a single entry.
Expected Behavior
Keys should only be converted to arrays when the same key appears multiple times within the same section. Identical keys in different sections must be treated independently and remain single values unless duplicated locally.
Steps To Reproduce
Steps to Reproduce
- Prepare the following INI content:
[section_1]
var = 1
[section_2]
var = 2
- Parse it using:
ini.parse(content, { bracketedArray: false });
- Observe the result:
{
section_1: { var: 1 },
section_2: { var: [2] }
}
- Notice that
section_2.var is returned as an array even though the key appears only once in that section.
Environment
- npm: 11.6.0
- Node: v22.19.0
- OS: windows 11
- platform: HP
Is there an existing issue for this?
Current Behavior
When parsing INI content with multiple sections that reuse the same key name:
calling:
returns:
{ Section_1: { var: 1 }, Section_2: { var: [2] } }As you can see, Section_2.var is incorrectly returned as an array, even though there is only a single value defined in that section.
I need bracketedArray for legacy compatibility—specifically, to support cases where multiple identical keys within the same section should be parsed as an array.
I believe the issue comes from using a global duplicate counter that is not scoped per section. In ini.js:
Because duplicates is tracked globally, keys with the same name across different sections are treated as duplicates, which causes later sections to be converted into arrays even when they contain only a single entry.
Expected Behavior
Keys should only be converted to arrays when the same key appears multiple times within the same section. Identical keys in different sections must be treated independently and remain single values unless duplicated locally.
Steps To Reproduce
Steps to Reproduce
section_2.varis returned as an array even though the key appears only once in that section.Environment