From 5732baeb972f74802251255e8aad86972a8bd7d5 Mon Sep 17 00:00:00 2001 From: Ricky Miller Date: Mon, 12 Feb 2018 11:17:01 -0600 Subject: [PATCH] Update Regex, add pledit with quotes --- js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT | 6 ++++++ js/utils.js | 2 +- js/utils.test.js | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT diff --git a/js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT b/js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT new file mode 100644 index 00000000..eb2fbdb3 --- /dev/null +++ b/js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT @@ -0,0 +1,6 @@ +[Text] +Normal= "#00FF00" +Current= '#FFFFFF' +NormalBG= "#000000" +SelectedBG= "#0000FF" +Font= "Ricky's cool font!" diff --git a/js/utils.js b/js/utils.js index f646d425..377bf5d7 100644 --- a/js/utils.js +++ b/js/utils.js @@ -78,7 +78,7 @@ export const parseIni = text => { let section, match; return text.split(/[\r\n]+/g).reduce((data, line) => { if ((match = line.match(PROPERTY_REGEX)) && section != null) { - const value = match[2].replace(/("|')/gi, ""); + const value = match[2].replace(/(^")|("$)|(^')|('$)/gi, ""); data[section][match[1].trim().toLowerCase()] = value; } else if ((match = line.match(SECTION_REGEX))) { section = match[1].trim().toLowerCase(); diff --git a/js/utils.test.js b/js/utils.test.js index 1fc4056b..ab8f69a7 100644 --- a/js/utils.test.js +++ b/js/utils.test.js @@ -145,6 +145,21 @@ bar = baz expect(actual).toEqual(expected); }); + it("can parse a pledit.txt file with quotes", () => { + const pledit = fixture("PLEDIT_WITH_QUOTES.TXT"); + const actual = parseIni(pledit); + const expected = { + text: { + normal: "#00FF00", + current: "#FFFFFF", + normalbg: "#000000", + selectedbg: "#0000FF", + font: "Ricky's cool font!" + } + }; + expect(actual).toEqual(expected); + }); + it("allows quotes around values", () => { const actual = parseIni(` [foo]