Skip to content

Commit

Permalink
Merge pull request #6 from nodecraft/fix/comment-writing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherry authored Dec 3, 2024
2 parents eb23f1d + 0e30c57 commit a7a6516
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const safe = (val, key, options = {}) => {
return val;
}
// comments
return val.replace(/;/g, '\\;').replace(/#/g, '\\#');
return val.replace(/\s;\s/g, '\\;').replace(/#/g, '\\#');
};

// unescapes the string val
Expand Down
7 changes: 4 additions & 3 deletions test/foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const expectE = 'o=p' + eol
+ 'x.y.z=xyz' + eol + eol
+ '[x\\.y\\.z.a\\.b\\.c]' + eol
+ 'a.b.c=abc' + eol
+ 'nocomment=this\\; this is not a comment' + eol
+ 'nocomment=this; this is not a comment' + eol
+ 'noHashComment=this\\# this is not a comment' + eol;
const expectEInlineArrays = 'o=p' + eol
+ 'a with spaces=b c' + eol
Expand Down Expand Up @@ -81,7 +81,7 @@ const expectEInlineArrays = 'o=p' + eol
+ 'x.y.z=xyz' + eol + eol
+ '[x\\.y\\.z.a\\.b\\.c]' + eol
+ 'a.b.c=abc' + eol
+ 'nocomment=this\\; this is not a comment' + eol
+ 'nocomment=this; this is not a comment' + eol
+ 'noHashComment=this\\# this is not a comment' + eol;
const expectforceStringifyKeys = 'o=p' + eol
+ 'a with spaces=b c' + eol
Expand Down Expand Up @@ -115,7 +115,7 @@ const expectforceStringifyKeys = 'o=p' + eol
+ 'x.y.z=xyz' + eol + eol
+ '[x\\.y\\.z.a\\.b\\.c]' + eol
+ 'a.b.c=abc' + eol
+ 'nocomment=this\\; this is not a comment' + eol
+ 'nocomment=this; this is not a comment' + eol
+ 'noHashComment=this\\# this is not a comment' + eol;
const expectExactValues = 'o=p' + eol
+ 'a with spaces=b c' + eol
Expand Down Expand Up @@ -409,5 +409,6 @@ test("unsafe escape values", function(t){
test("safe escape tests", function(t){
t.equal(ini.safe('abc'), 'abc');
t.equal(ini.safe('abc', 'someKey', {forceStringifyKeys: ['someKey']}), '"abc"');
t.equal(ini.safe('x;y'), 'x;y');
t.end();
});

0 comments on commit a7a6516

Please sign in to comment.