Skip to content

fix: scope duplicate key tracking per section with bracketedArray=false#299

Open
abhu85 wants to merge 1 commit intonpm:mainfrom
abhu85:fix/scope-duplicates-per-section
Open

fix: scope duplicate key tracking per section with bracketedArray=false#299
abhu85 wants to merge 1 commit intonpm:mainfrom
abhu85:fix/scope-duplicates-per-section

Conversation

@abhu85
Copy link

@abhu85 abhu85 commented Feb 23, 2026

Summary

Fixes #298

When using bracketedArray: false, the duplicate key counter was global across all sections, causing keys with the same name in different sections to be incorrectly converted to arrays.

The Problem

[section_1]
var = 1

[section_2]
var = 2

Was incorrectly parsed as:

{ section_1: { var: '1' }, section_2: { var: ['2'] } }  // ❌ var is wrongly an array

Because the global duplicates counter saw var twice across both sections.

The Fix

Reset the duplicates counter when entering a new section (line 128), so keys are only treated as duplicates when they appear multiple times within the same section.

Now correctly parses as:

{ section_1: { var: '1' }, section_2: { var: '2' } }  // ✅ both are scalars

Changes

  • lib/ini.js: Change duplicates from const to let, reset to {} when entering new section
  • test/duplicate-properties.js: Add regression tests for cross-section and within-section duplicates

Test Results

All tests pass with 100% coverage.


Fixes npm#298

When using `bracketedArray: false`, the duplicate key counter was global across
all sections, causing keys with the same name in different sections to be
incorrectly converted to arrays.

For example:
```ini
[section_1]
var = 1

[section_2]
var = 2
```

Was incorrectly parsed as:
```js
{ section_1: { var: '1' }, section_2: { var: ['2'] } }
```

The fix resets the duplicates counter when entering a new section, so keys are
only treated as duplicates when they appear multiple times within the same section.

Now correctly parses as:
```js
{ section_1: { var: '1' }, section_2: { var: '2' } }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] bracketedArray: false produces arrays for duplicate keys across sections

1 participant