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

add NoMultiLineSurroundingQuotes option #331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benbaker76
Copy link

Describe the pull request

Consider the following multi-line ini file:

value1 = some text here
	some more text here 2

Run the following code:

path := "multiline_eof.ini"
f, _ := ini.LoadSources(ini.LoadOptions{
  AllowPythonMultilineValues: true,
}, path)

f.Section("").Key("value1").SetValue("some text here\n\tsome more text here 2")
f.SaveTo(path)

Will output:

value1 = """some text here
	some more text here 2"""

Now run:

path := "multiline_eof.ini"
f, _ := ini.LoadSources(ini.LoadOptions{
  AllowPythonMultilineValues: true,
  NoMultiLineSurroundingQuotes: true,
}, path)

f.Section("").Key("value1").SetValue("some text here\n\tsome more text here 2")
f.SaveTo(path)

The output is the same as the original file

value1 = some text here
	some more text here 2

Link to the issue: n/a

Checklist

  • [*] I agree to follow the Code of Conduct by submitting this pull request.
  • [*] I have read and acknowledge the Contributing guide.
  • [*] I have added test cases to cover the new code.

Copy link

@aghandri aghandri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for suggesting this change, it is indeed a very handy option, especially when used to generate aws config files.

However, the result of your changes still keeps the surrounding double quotes if the value contains leading and trailing white spaces.

Here is the result I obtained:

duration_seconds    = xxxxxxx
s3                  = "
        signature_version = version"

To remove these double quotes, I suggest to add the condition on line 467:

} else if !f.options.NoMultiLineSurroundingQuotes && len(strings.TrimSpace(val)) != len(val) {
	val = `"` + val + `"`
}

The result would be:

duration_seconds    = xxxxxxx
s3                  = 
        signature_version = version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants