diff --git a/ini.js b/ini.js index 6aa3833..7f6a1e5 100644 --- a/ini.js +++ b/ini.js @@ -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 diff --git a/test/foo.js b/test/foo.js index 1da735c..985683f 100644 --- a/test/foo.js +++ b/test/foo.js @@ -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 @@ -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 @@ -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 @@ -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(); }); \ No newline at end of file