From 23818c3e1b84446aea950ceb54d3a43b0297c0b1 Mon Sep 17 00:00:00 2001 From: Andrej Beliakov Date: Thu, 18 Oct 2018 13:43:39 +0300 Subject: [PATCH 1/6] allow sections containing a dot to be queried --- .gitignore | 1 + README.md | 3 ++- lib/simple-ini.js | 55 ++++++++++++++++++++++++++--------------------- 3 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md index 9d7cd3f..2692916 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,10 @@ API Documentation * hasProperty(property, section) - checks if the property exists in the section. If the section is not specified then it checks if global property exists. -* get(config) - Gets property's value. config might be 'section.property' or +* get(section, property?) - Gets property's value. config might be 'section.property' or just 'property'. If the config is just a 'property' then the library tries to get the global property. + Section names containing dots have to be queried by delimiting the section and property part as proper arguments Options ------- diff --git a/lib/simple-ini.js b/lib/simple-ini.js index 24f8e94..70c9fda 100644 --- a/lib/simple-ini.js +++ b/lib/simple-ini.js @@ -223,37 +223,42 @@ var SimpleIni = (function () { this, "get", { - value: function(config) { - var section, - property, - isIgnoreCase, - delimiter; - - isIgnoreCase = !finalOptions.caseSensitive; - delimiter = config.indexOf('.'); - if (delimiter > -1) { - section = config.substr(0, delimiter); - property = config.substr(delimiter + 1); - + value: function(section, property) { + var isIgnoreCase = !finalOptions.caseSensitive; + if(!property){ + var delimiter; + + delimiter = section.indexOf('.'); + if (delimiter > -1) { + section = section.substr(0, delimiter); + property = section.substr(delimiter + 1); + + section = findProperty(self, section, isIgnoreCase); + if (section !== null) { + property = findProperty(self[section], property, isIgnoreCase); + return property === null ? property : self[section][property]; + } + } + else { + section = findProperty(self, section, isIgnoreCase); + if (section != null) { + property = self[section]; + if (!finalOptions.allowGlobalProperties || + (finalOptions.allowGlobalProperties && + (typeof property === 'string' || + typeof property === 'number' || + typeof property === 'boolean'))) { + return property; + } + } + } + } else { section = findProperty(self, section, isIgnoreCase); if (section !== null) { property = findProperty(self[section], property, isIgnoreCase); return property === null ? property : self[section][property]; } } - else { - section = findProperty(self, config, isIgnoreCase); - if (section != null) { - property = self[section]; - if (!finalOptions.allowGlobalProperties || - (finalOptions.allowGlobalProperties && - (typeof property === 'string' || - typeof property === 'number' || - typeof property === 'boolean'))) { - return property; - } - } - } return null; } From 8913040b6afd18f2983302127f8e14284a77ed44 Mon Sep 17 00:00:00 2001 From: localh0rzd Date: Thu, 18 Oct 2018 17:08:08 +0300 Subject: [PATCH 2/6] increase version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ebc975..ef88c77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-ini", - "version": "1.0.4", + "version": "1.0.5", "description": "Simple INI-parser", "main": "./lib/simple-ini.js", "homepage": "https://github.com/ilich/simple-ini", From 00786b92d714690a342f1d2fe64d3b7d4bc9b375 Mon Sep 17 00:00:00 2001 From: localh0rzd Date: Thu, 18 Oct 2018 17:10:19 +0300 Subject: [PATCH 3/6] fix readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2692916..9f6bb92 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ API Documentation * hasProperty(property, section) - checks if the property exists in the section. If the section is not specified then it checks if global property exists. -* get(section, property?) - Gets property's value. config might be 'section.property' or - just 'property'. If the config is just a 'property' then the library tries to get +* get(section, property?) - Gets property's value. section might be 'section.property' or + just 'property'. If the section is just a 'property' then the library tries to get the global property. Section names containing dots have to be queried by delimiting the section and property part as proper arguments From cbf01ac9c18467e5f51e6babe77df04f393f13e4 Mon Sep 17 00:00:00 2001 From: localh0rzd Date: Mon, 22 Oct 2018 12:08:30 +0300 Subject: [PATCH 4/6] fix order of variable assignment --- lib/simple-ini.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple-ini.js b/lib/simple-ini.js index 70c9fda..662a53b 100644 --- a/lib/simple-ini.js +++ b/lib/simple-ini.js @@ -230,8 +230,8 @@ var SimpleIni = (function () { delimiter = section.indexOf('.'); if (delimiter > -1) { - section = section.substr(0, delimiter); property = section.substr(delimiter + 1); + section = section.substr(0, delimiter); section = findProperty(self, section, isIgnoreCase); if (section !== null) { From bebd9cc9a62726a3910ba0f0d604dd02db48d156 Mon Sep 17 00:00:00 2001 From: Andrej Beliakov Date: Fri, 22 Feb 2019 11:37:04 +0100 Subject: [PATCH 5/6] Allow parsing ini files having non-compliant multiline entries --- lib/simple-ini.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/simple-ini.js b/lib/simple-ini.js index 662a53b..a12ee15 100644 --- a/lib/simple-ini.js +++ b/lib/simple-ini.js @@ -274,7 +274,19 @@ var SimpleIni = (function () { } content = loadFunction().split(finalOptions.lineSeparator); - + + // Allow parsing ini files having non-compliant multiline entries + for (let [index, val] of content.entries()) { + if (!/(\[.+\]|=)/.test(val)) { + let tempindex = index - 1; + while (!content[tempindex].includes("=")) { + tempindex -= 1; + } + content[tempindex] += `\n${ val }`; + content[index] = ""; + } + } + content = content.filter(x => x != ""); sectionName = null; next_line: From a18890812bcf8cfb85e9dddf5d79b15898a29ba9 Mon Sep 17 00:00:00 2001 From: Andrej Beliakov Date: Mon, 25 Feb 2019 14:14:48 +0100 Subject: [PATCH 6/6] fix empty line handling in simple-ini --- lib/simple-ini.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/simple-ini.js b/lib/simple-ini.js index a12ee15..45c2cd3 100644 --- a/lib/simple-ini.js +++ b/lib/simple-ini.js @@ -277,11 +277,12 @@ var SimpleIni = (function () { // Allow parsing ini files having non-compliant multiline entries for (let [index, val] of content.entries()) { - if (!/(\[.+\]|=)/.test(val)) { - let tempindex = index - 1; + if (!/(\[.+\]|=)/.test(val) && val) { + let tempindex = index - 1 while (!content[tempindex].includes("=")) { tempindex -= 1; } + content[tempindex] += `\n${ val }`; content[index] = ""; } @@ -378,4 +379,4 @@ var SimpleIni = (function () { if (typeof module != 'undefined') { module.exports = SimpleIni; -} \ No newline at end of file +}