Comparing version 1.0.2 to 1.0.3
24
ini.js
@@ -26,3 +26,4 @@ | ||
children.forEach(function (k, _, __) { | ||
var child = encode(obj[k], (section ? section + "." : "") + k) | ||
var nk = dotSplit(k).join('\\.') | ||
var child = encode(obj[k], (section ? section + "." : "") + nk) | ||
if (out.length && child.length) { | ||
@@ -37,2 +38,11 @@ out += "\n" | ||
function dotSplit (str) { | ||
return str.replace(/\1/g, '\2LITERAL\\1LITERAL\2') | ||
.replace(/\\\./g, '\1') | ||
.split(/\./).map(function (part) { | ||
return part.replace(/\1/g, '\\.') | ||
.replace(/\2LITERAL\\1LITERAL\2/g, '\1') | ||
}) | ||
} | ||
function decode (str) { | ||
@@ -62,2 +72,7 @@ var out = {} | ||
, value = match[3] ? unsafe((match[4] || "")) : true | ||
switch (value) { | ||
case 'true': | ||
case 'false': | ||
case 'null': value = JSON.parse(value) | ||
} | ||
p[key] = value | ||
@@ -72,5 +87,6 @@ }) | ||
// if so, add it to that, and mark this one for deletion | ||
var parts = k.split(".") | ||
var parts = dotSplit(k) | ||
, p = out | ||
, l = parts.pop() | ||
, nl = l.replace(/\\\./g, '.') | ||
parts.forEach(function (part, _, __) { | ||
@@ -80,4 +96,4 @@ if (!p[part] || typeof p[part] !== "object") p[part] = {} | ||
}) | ||
if (p === out) return false | ||
p[l] = out[k] | ||
if (p === out && nl === l) return false | ||
p[nl] = out[k] | ||
return true | ||
@@ -84,0 +100,0 @@ }).forEach(function (del, _, __) { |
@@ -5,3 +5,3 @@ { | ||
"description": "An ini encoder/decoder for node", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"repository": { | ||
@@ -13,3 +13,3 @@ "type": "git", | ||
"scripts": { | ||
"test": "node ini.js" | ||
"test": "tap test/*.js" | ||
}, | ||
@@ -22,6 +22,3 @@ "engines": { | ||
"tap": "~0.0.9" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
} | ||
} |
@@ -20,3 +20,6 @@ var i = require("../") | ||
+ ' \\"a val\\", b: { c: { e: \\"this [value]' | ||
+ '\\" } } } }\\""\n"[]" = a square?\n\n[a.b.c]\ne = 1\nj = 2\n' | ||
+ '\\" } } } }\\""\n"[]" = a square?\n\n[a.b.c]\ne = 1\n' | ||
+ 'j = 2\n\n[x\\.y\\.z]\nx.y.z = xyz\n\n' | ||
+ '[x\\.y\\.z.a\\.b\\.c]\n' | ||
+ 'a.b.c = abc\n' | ||
, expectD = | ||
@@ -32,3 +35,9 @@ { o: 'p', | ||
"[]": "a square?", | ||
b: { c: { e: '1', j: '2' } } } | ||
b: { c: { e: '1', j: '2' } } }, | ||
'x.y.z': { | ||
'x.y.z': 'xyz', | ||
'a.b.c': { | ||
'a.b.c': 'abc' | ||
} | ||
} | ||
} | ||
@@ -35,0 +44,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9382
7
176
0