ini icon indicating copy to clipboard operation
ini copied to clipboard

Section headers with '.' in them are split

Open ankon opened this issue 9 years ago • 5 comments

I have the following .ini file:

[https://www.example.com]
settingA = foo
settingB = bar

When parsing this .ini the resulting structure has the section header cut into pieces, I expected {'https://www.example.com': { settingA: 'foo', settingB: 'bar' } }, but got {'https://www': { 'example': { 'com': { settingA: 'foo', settingB: 'bar' } } } }.

ankon avatar Jul 18 '16 12:07 ankon

Reading through the test directory it seems this is a feature, not a bug. Maybe it would be worthwhile to be more explicit about it in the documentation, especially also how to try to escape the values (the source of the .ini file seems to actually be happy with me escaping the '.' characters using a '').

ankon avatar Jul 18 '16 13:07 ankon

For what it's worth, I'm working on a PR for this, but it will be a few days or weeks before I submit it.

The intended approach is to add a sectionDelimiter option which is . by default, but which could be set to another character or null in order to change the behavior accordingly.

platinumazure avatar Feb 28 '18 05:02 platinumazure

It's really very important:

[my.site.com]
user=admin
password=mypassword

alex-shamshurin avatar May 18 '18 13:05 alex-shamshurin

What's the status on this? I would also need the functionality to skip the splitting.

BamButz avatar Jan 10 '20 10:01 BamButz

I've hit this bug as well, I would be fine with a way to disable splitting instead of changing the delimiter but as it is right now this is preventing me from using this library but I cant find any other useful ini parser either.

ext avatar Apr 18 '20 10:04 ext

Just post process the data, I provided a solution here https://github.com/npm/ini/issues/22#issuecomment-1426581205 (can probably be improved but it works. I don't foresee the creators of the package changing it anytime soon they are strictly following the ini specification.

rehanvdm avatar Feb 14 '23 14:02 rehanvdm

Carrying on from @rehanvdm's comment, Section Nesting, it would seem every symbol in a URL is bad for this as all of them have been used to infer a hierarchy. Which is sort of true (https://github.com/npm/ini/issues/60 contains a hierarchy of information ... if you want to read it that way).

So, whilst the soft standard allows for these symbols, having the option to use a nominated symbol for the hierarchical sections or the ability to disable the hierarchical sections seem to be the only 2 options.

rquadling avatar Mar 22 '23 11:03 rquadling

There was a PR that attempted to address this but it had some unanswered questions in it.

If folks want to take a run at introducing a new option to set this delimiter, or disable the behavior altogether they are welcome to.

As of now folks can escape those strings like ini would if it were serializing the object itself.

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

wraithgar avatar Apr 13 '23 17:04 wraithgar