Skip to content

using []string in a struct goes wrong if any of the strings contains a comma ',' #348

Closed

Description

@mark-summerfield

Version

go version go1.21.4 linux/amd64

Describe the bug

I have a struct:

type Config struct {
	Scale    float32
	History  []string
}

This normally works fine with ini.ReflectFrom and ini.Load. However if one of the strings has a comma ',' it doesn't work correctly.

To reproduce

Try a .ini file like this:

Scale = 1.5
History = Test One,Test Two,Test with comma, Three,Test Four

Expected behavior

I expect it to quote commas on save and unquote them on load.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added a commit that references this issue on Nov 11, 2026
    6480996
  2. unknwon commented on Nov 11, 2026

    @unknwon
    Member

    Fixed in v1.68.0 by PR 402. Set LoadOptions{EscapeSliceDelimiters: true} and ReflectFrom escapes \ and the delimiter in string slice elements, so MapTo reads them back unchanged. It is off by default in v1 because other readers don't unescape them. v2 (unknwon.dev/ini/v2) escapes by default.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions