diff options
author | isaacs <i@izs.me> | 2012-10-04 21:35:10 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-10-04 21:35:10 +0400 |
commit | d05e632b55f42a366ea62ac26c903546e05ab15b (patch) | |
tree | 0157678e6cb4933ab73a2618bae7532681b89c7a /node_modules/ini/ini.js | |
parent | 237b95328ed6863c2e5efd370cc0940fd60b72f2 (diff) |
ini@1.0.5
fix #2852
Diffstat (limited to 'node_modules/ini/ini.js')
-rw-r--r-- | node_modules/ini/ini.js | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/node_modules/ini/ini.js b/node_modules/ini/ini.js index 7939f20e5..45651c03f 100644 --- a/node_modules/ini/ini.js +++ b/node_modules/ini/ini.js @@ -56,10 +56,7 @@ function decode (str) { , section = null lines.forEach(function (line, _, __) { - //line = line - var rem = line.indexOf(";") - if (rem !== -1) line = line.substr(0, rem)//.trim() - if (!line) return + if (!line || line.match(/^\s*;/)) return var match = line.match(re) if (!match) return if (match[1] !== undefined) { @@ -108,13 +105,38 @@ function safe (val) { || (val.length > 1 && val.charAt(0) === "\"" && val.slice(-1) === "\"") - || val !== val.trim() ) ? JSON.stringify(val) : val + || val !== val.trim() ) + ? JSON.stringify(val) + : val.replace(/;/g, '\\;') } -function unsafe (val) { +function unsafe (val, doUnesc) { val = (val || "").trim() if (val.charAt(0) === "\"" && val.slice(-1) === "\"") { try { val = JSON.parse(val) } catch (_) {} + } else { + // walk the val to find the first not-escaped ; character + var esc = false + var unesc = ""; + for (var i = 0, l = val.length; i < l; i++) { + var c = val.charAt(i) + if (esc) { + if (c === "\\" || c === ";") + unesc += c + else + unesc += "\\" + c + esc = false + } else if (c === ";") { + break + } else if (c === "\\") { + esc = true + } else { + unesc += c + } + } + if (esc) + unesc += "\\" + return unesc } return val } |