Skip to content

Cannot read duplicate keys in INI file #283

Description

@UnixGuru

Describe the bug
With gopkg.in/ini.v1, v1.62.0, you cannot read duplicate keys in same section.

To Reproduce
Use this INI file snippet:

[test]
        Key1=Key1Value1
        Key1=Key1Value2
        Key2=Key2Value1
        Key2=Key2Value2

Using this code:

package main

import (
    "fmt"
    "os"

    "gopkg.in/ini.v1"
)

func main() {
    cfg, err := ini.Load("test.ini")
    if err != nil {
        fmt.Printf("Fail to read file: %v", err)
        os.Exit(1)
    }

    for _, section := range cfg.Sections() {
       for _, key := range section.Keys() {
          fmt.Printf("section[%s], key=[%s], value=[%s]\n", section.Name(), key.Name(), key.Value())
        }       
   }
}

Produces output like this:

section[test], key=[Key1], value=[Key1Value2]
section[test], key=[Key2], value=[Key2Value2]

Expected behavior

I'd like to be able to see this:

section[test], key=[Key1], value=[Key1Value1]
section[test], key=[Key1], value=[Key1Value2]
section[test], key=[Key2], value=[Key2Value1]
section[test], key=[Key2], value=[Key2Value2]

Additional context
I also tried this to in place of Load() with the same results

cfg, err := ini.LoadSources(ini.LoadOptions{AllowShadows: true}, "test.ini")

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