Skip to content

Commit 9334f40

Browse files
authored
Merge pull request #1067 from Jonnymcc/fix-parse-ini-comments
Parse ini files with comments starting with #
2 parents a97c2ba + 9baf002 commit 9334f40

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "util",
4+
"description": "Parse ini files containing comments using #"
5+
}

lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ var util = {
189189
parse: function string(ini) {
190190
var currentSection, map = {};
191191
util.arrayEach(ini.split(/\r?\n/), function(line) {
192-
line = line.split(/(^|\s);/)[0]; // remove comments
192+
line = line.split(/(^|\s)[;#]/)[0]; // remove comments
193193
var section = line.match(/^\s*\[([^\[\]]+)\]\s*$/);
194194
if (section) {
195195
currentSection = section[1];

test/util.spec.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,14 @@ describe 'AWS.util.ini', ->
207207
invalidline
208208
key1=value1 ; another comment
209209
key2 = value2;value3
210+
key3 = value4 # yet another comment
210211
[emptysection]
212+
#key1=value1
211213
'''
212214
map = AWS.util.ini.parse(ini)
213215
expect(map.section1.key1).to.equal('value1')
214216
expect(map.section1.key2).to.equal('value2;value3')
217+
expect(map.section1.key3).to.equal('value4')
215218
expect(map.emptysection).to.equal(undefined)
216219

217220
it 'ignores leading and trailing white space', ->

0 commit comments

Comments
 (0)