Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReflectFrom does not work properly with AllowNonUniqueSections set to true #311

Open
floriankramer opened this issue Dec 14, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@floriankramer
Copy link

floriankramer commented Dec 14, 2021

Describe the bug
When enabling AllowNonUniqueSections and using SectionWithIndex(name, idx).ReflectFrom to create several sections with the same name from a struct the call to ReflectFrom deletes any previously created sections with the same name.

To Reproduce

package main

import (
	"fmt"

	"gopkg.in/ini.v1"
)

type T struct {
	value string
}

func main() {
	var opts ini.LoadOptions
	opts.AllowNonUniqueSections = true

	cfg := ini.Empty(opts)
	for i := 0; i < 10; i++ {
		data := T{
			value: "test",
		}

		err := cfg.SectionWithIndex("Test", i).ReflectFrom(&data)
		if err != nil {
			panic(err)
		}
	}

	sections, _ := cfg.SectionsByName("Test")
	fmt.Println("Number of test sections", len(sections))
}

Expected behavior
Several sections should exist after running ReflectFrom several times.

@unknwon unknwon added the bug Something isn't working label Dec 15, 2021
@dwmunster
Copy link
Contributor

According to the test Test_ReflectFromStructNonUnique, this seems to be intended behavior. In particular,

		// note: using ReflectFrom from should overwrite the existing sections

I also found this behavior to be unexpected. In my context, I was looking to overwrite/update a single non-unique section with ReflectFrom but that will delete all the other matching sections in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants