Skip to content

Cannot Read Duplicate Values for Shadowed Keys #284

Description

@dwmunster

Describe the bug
Duplicate values for shadowed keys are not preserved in either ValueWithShadows() or just WriteTo().

To Reproduce

package main

import (
	"os"

	"gopkg.in/ini.v1"
)

const f = `[test]
Key1=Key1Value1
Key1=Key1Value2
Key1=Key1Value1
`

func main() {
	cfg, _ := ini.ShadowLoad([]byte(f))
	cfg.WriteTo(os.Stdout)
}

produces

[test]
Key1 = Key1Value1
Key1 = Key1Value2

Expected behavior
Reading in the file should not destroy the duplicate line. WriteTo() should reproduce the source file:

[test]
Key1 = Key1Value1
Key1 = Key1Value2
Key1 = Key1Value1

Additional context
While similarly named, this is not a duplicate of #283 which is a case of needing ValueWithShadows().

I am working with a save file for a game that is stored in an INI format. Extra equipment may be stored in the cargo with lines such as

cargo                = 2322110156, 1, , , 0
cargo                = 2859002568, 1, , , 0
cargo                = 2859002568, 1, , , 0

where the last two duplicate lines indicate additional quantity. Currently, go-ini is mangling the duplicate lines resulting in the loss of equipment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions