ini icon indicating copy to clipboard operation
ini copied to clipboard

Quoting values in written file

Open via-justa opened this issue 5 years ago • 4 comments

Describe the bug Writing ini file from struct not allowing to quote string values. There is the option PreserveSurroundedQuote to keep quotes in the loadOptions but as I don't load the values from file but from struct, I cannot use that option. My code is creating a config file that later a php code will use. The PHP specify that

If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes (").

Is there a way that I missed to force the values to be quoted?

To Reproduce https://play.golang.org/p/TwJgeMWf6zW

Expected behavior All string values will be quoted

via-justa avatar Feb 14 '20 10:02 via-justa

For context, if there is no special character in the key or value that will confuse this library later (at parsing stage), there will be no quotes added automatically.

unknwon avatar Feb 16 '20 04:02 unknwon

Just to note, strings with special characters are currently getting "`" around them, that can break the configuration for other lang other than PHP as well. In my opinion the minimum should be to quote strings with escaped characters and set the quotation to double quotes as it's the most common. The ideal solution will be to add a user config option to set how to treat strings (like defining what are special characters that needs the string to be quoted and what quotation to use)

via-justa avatar Feb 16 '20 19:02 via-justa

Is there a fix or work-around for the key names being wrapped in "`" ? It's breaking my code.

jlagermann avatar Feb 11 '22 00:02 jlagermann

Is there a fix or work-around for the key names being wrapped in "`" ? It's breaking my code.

@jlagermann I am not sure if you're commenting on the right thread.

unknwon avatar Feb 11 '22 03:02 unknwon

It looks like this ticket does not get much traction so I’ll close it now

via-justa avatar Sep 24 '22 14:09 via-justa