Skip to content

@std/ini parse silently drops an entire section when the section name repeats #7360

Open

Description

@Harsh23Kashyap

Describe the bug

When an INI document contains the same section header twice, parse keeps only the last occurrence's keys. The earlier section's keys vanish without an error, so a valid config loses settings silently.

Reproduction

import { parse } from "jsr:@std/ini";

parse("[s]\na=1\n[s]\nb=2");
// -> { s: { b: 2 } }   (a=1 is gone)

parse("[db]\nhost=a\nport=1\n[db]\nuser=b");
// -> { db: { user: "b" } }   (host and port are gone)

Expected behavior

Other mainstream INI parsers do not lose the earlier content:

  • node-ini merges repeated sections: { s: { a: "1", b: "2" } }
  • Python's configparser raises DuplicateSectionError (in strict mode, the default)

Either merging or raising protects the caller; silently discarding the first section does not. Repeated sections can appear when config files are concatenated or appended to, so this is reachable in practice, not just hand-written edge cases.

Environment

  • @std/ini (JSR, latest)
  • Node 22 for the harness; the code path is engine-independent

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions