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

Allow empty key values #342

Open
1 task done
UnixGuru opened this issue Jun 12, 2023 · 0 comments
Open
1 task done

Allow empty key values #342

UnixGuru opened this issue Jun 12, 2023 · 0 comments
Labels
feature Categorizes as related to a new feature

Comments

@UnixGuru
Copy link

Describe the feature

We have a condition where our INI files have something like this example:

[section]
Key1=value1
Key2=
Key3=value3

We use code something like:

for _, section := cfg.Sections() {
// deal with some of the sections, per key, then...
for _, key := section.Keys() {
for _, value := key.ValueWithShadows() {

You get the idea. Anyway, we never see "Key2".
What I would like to have is an option where I get "Key2" with an empty string as the value.

Describe the solution you'd like

We'd like some sort of option we could add into the LoadSources, something like:

cfg, err := ini.LoadSources(ini.LoadOptions{AllowBlankValues: true, AllowShadows: true, SkipUnrecognizableLines: true, SpaceBeforeInlineComment: true}, outbytes.Bytes())

With a default of false, you keep the current way of not handling blank values.

Describe alternatives you've considered

As a work around, part of our syntax for the value allows some options, we enclose in curly braces, so we can make the INI parse with something like

[section]
Key1=value1
Key2={}
Key3=value3

Now, I get Key2 with a value of "{}". It would be nice not to have to have to do this.

So, if we could get a new LoadOptions setting, that would be groovy.

Additional context

Feel free to contact me if you have questions.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@UnixGuru UnixGuru added the feature Categorizes as related to a new feature label Jun 12, 2023
@UnixGuru UnixGuru changed the title Allow empty keys Allow empty key values Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Categorizes as related to a new feature
Projects
None yet
Development

No branches or pull requests

1 participant