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 option to set custom section delimiter #95

Closed
wants to merge 1 commit into from
Closed

Conversation

ext
Copy link

@ext ext commented Apr 18, 2020

What / Why

Adds an option to set or disable delimiter used when splitting sections into nested objets.

While splitting sections can be useful in some cases it also prevents others such as sections with URLs or paths:

[http://example.net]
...

[myfile.txt]
...

While it is possible to escape the dots using myfile\.txt for this parser it may break other libraries, e.g. when the ini-file is used written/read by some other tool. In my case I receive the ini-file from an integration and have no control over it.

It PR allows setting a custom delimiter or to disable splitting entirely (for reading, writing still requires a delimiter).

References

foo: '1'
}
},
'c.d': {
Copy link
Member

Choose a reason for hiding this comment

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

This seems wrong.

@wraithgar
Copy link
Member

Cleaning up old PRs and came to this one. Rebased and cleaned it up after landing #200.

However this brings up more questions such as, "should the decoded object have dot separated sections still?" This PR seems to suggest that but that seems counterintuitive.

If the problem being solved is that dots in sections don't work, this appears to be something that is feasible now:

> ini.encode(ini.decode('[http:example\\.net]\ndots=true'))
'[http:example\\.net]\ndots=true\n'
> ini.decode('[http:example\\.net]\ndots=true')
[Object: null prototype] {
  'http:example.net': [Object: null prototype] { dots: true }
}

The question to answer before a PR like this can be made is "is the delimiter kept in the decoded object?" A note on the test where this comes up has been added.

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.

Section headers with '.' in them are split
2 participants