node-iniparser icon indicating copy to clipboard operation
node-iniparser copied to clipboard

Feature request: Allow comments

Open andyuk opened this issue 14 years ago • 9 comments

Thanks for this nice module. I have a little feature request.

Would you be able to add support for comments? I think the standard for .ini file is a semi-colon isn't it?

  • Andrew

andyuk avatar Oct 25 '11 15:10 andyuk

Hi,

Thanks for the feature request, I'm not really sure why you want to parse the comments. If they have valuable information, why don't you make them a variable? Also how can you identify a comment? values have keys and sections but a comment has no key to identify them.

shockie avatar Oct 27 '11 18:10 shockie

I think you have mis-understood me. I don't want comments to be parsed. It looks like semi-colon quotes are not supported. Am I missing something?

I just want to be able to do something like:

; here is a comment that explains about this setting
key=value

andyuk avatar Oct 27 '11 19:10 andyuk

Ah yes, i've mis-understood you. Comments are left out of the parsed data, so you can add comments in the .ini file. i've added a test case in the test suite to test for comment parsing.

shockie avatar Oct 31 '11 21:10 shockie

I've just tested this again and found there is a bug (which is why I reported this in the first place).

[category]
; here is a comment that explains about this setting
key=value

this will produce the json:

{
category {},
key: value
}

it should be:

{
category {
  key: value
  }
}

Thanks for looking at this.

Andrew

andyuk avatar Nov 01 '11 18:11 andyuk

Hmm strange,

I'm using node 0.4.12 and node-iniparser 1.0.4 and can't reproduce this problem. Can you run this piece of code and tell me what it returns? (example.ini is you piece of ini, you've mentioned earlier and run this code in the root of your git checkout)

var iniparser = require('./lib/node-iniparser');
var config = iniparser.parseSync('./test/files/example.ini');
console.log(config.category.key);

What version are you using, and which node version?

shockie avatar Nov 02 '11 20:11 shockie

That example you provided worked fine. I've found the issue. It's the blank lines that causes the problem. Try the following example. That will return "undefined" for config.category.key.

[category]
; comment

key=value

andyuk avatar Nov 04 '11 14:11 andyuk

I know what you mean but if it's a bug, I don't know. based on the article on wikipedia http://en.wikipedia.org/wiki/INI_file, I define the blank line as a break of the section. How can I otherwise determine if the section has ended, double white line?

shockie avatar Nov 09 '11 19:11 shockie

Hi again,

We've just had an issue with our server admin not realising that double white space lines are not allowed.

It's great that you are following the specs so closely, however in this case, this feels like a bug. A section should be indicated by the start of a new [section].

eg.

key=value
[section]
section=true


section=still-true

That would mean it wouldn't be possible to add more keys and values that are not in a section if a section has already been started. I think that's OK since those keys/values should be at the top anyway.

What do you think?

Thanks for your efforts on this library by the way, it's been really helpful for us. :)

Cheers, Andrew

andyuk avatar Dec 02 '11 18:12 andyuk

Good point, as more requests are coming in on parsing different types of ini formats, I think it's time to make the parsing more configurable. ie set config flags like allowDoubleWhite:true on the constructor or make different parsing 'engines'. Anyhow it's time to set a standard.

shockie avatar Dec 05 '11 10:12 shockie