npm / ini

An ini parser/serializer in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Section headers with '.' in them are split

ankon opened this issue · 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' } } } }.

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 '').

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.

It's really very important:

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

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

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.

Just post process the data, I provided a solution here #22 (comment) (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.

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.

commented

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'