diff --git a/js/__snapshots__/regionParser.test.js.snap b/js/__snapshots__/regionParser.test.js.snap index ebbee1ca..d11db1c9 100644 --- a/js/__snapshots__/regionParser.test.js.snap +++ b/js/__snapshots__/regionParser.test.js.snap @@ -422,3 +422,32 @@ Object { ], } `; + +exports[`regionParser parses the iTuned region.txt 1`] = ` +Object { + "equalizer": Array [ + "5,0 269,0 269,116 5,116", + "3,1 5,1 5,115 3,115", + "2,2 4,2 4,114 2,114", + "1,3 4,3 4,113 1,113", + "0,5 5,5 5,111 0,111", + "267,1 271,1 271,115 267,115", + "267,2 272,2 272,114 267,114", + "267,3 273,3 273,113 267,113", + "267,4 274,4 274,112 267,112", + "267,6 275,6 275,111 267,111", + ], + "normal": Array [ + "5,0 269,0 269,116 5,116", + "3,1 5,1 5,115 3,115", + "2,2 4,2 4,114 2,114", + "1,3 4,3 4,113 1,113", + "0,5 5,5 5,111 0,111", + "267,1 271,1 271,115 267,115", + "267,2 272,2 272,114 267,114", + "267,3 273,3 273,113 267,113", + "267,4 274,4 274,112 267,112", + "267,6 275,6 275,111 267,111", + ], +} +`; diff --git a/js/__tests__/fixtures/region_ituned.txt b/js/__tests__/fixtures/region_ituned.txt new file mode 100755 index 00000000..bc928e59 --- /dev/null +++ b/js/__tests__/fixtures/region_ituned.txt @@ -0,0 +1,7 @@ +[Normal] +NumPoints = 4,4,4,4,4,4,4,4,4,4 +PointList = 5,0, 269,0, 269,116, 5,116, 3,1 5,1, 5,115, 3,115, 2,2, 4,2, 4,114, 2,114, 1,3, 4,3, 4,113, 1,113, 0,5, 5,5, 5,111, 0,111, 267,1, 271,1 271,115, 267,115, 267,2, 272,2, 272,114, 267,114, 267,3, 273,3, 273,113, 267,113, 267,4, 274,4, 274,112, 267,112, 267,6, 275,6, 275,111, 267,111, + +[Equalizer] +NumPoints = 4,4,4,4,4,4,4,4,4,4 +PointList = 5,0, 269,0, 269,116, 5,116, 3,1 5,1, 5,115, 3,115, 2,2, 4,2, 4,114, 2,114, 1,3, 4,3, 4,113, 1,113, 0,5, 5,5, 5,111, 0,111, 267,1, 271,1 271,115, 267,115, 267,2, 272,2, 272,114, 267,114, 267,3, 273,3, 273,113, 267,113, 267,4, 274,4, 274,112, 267,112, 267,6, 275,6, 275,111, 267,111, diff --git a/js/regionParser.test.js b/js/regionParser.test.js index 091e8cc0..b62b8e8f 100644 --- a/js/regionParser.test.js +++ b/js/regionParser.test.js @@ -38,4 +38,11 @@ describe("regionParser", () => { ); expect(regionParser(regionTxt)).toMatchSnapshot(); }); + it("parses the iTuned region.txt", () => { + const regionTxt = fs.readFileSync( + "./js/__tests__/fixtures/region_ituned.txt", + "utf8" + ); + expect(regionParser(regionTxt)).toMatchSnapshot(); + }); }); diff --git a/js/utils.js b/js/utils.js index 377d08a2..f05a92f1 100644 --- a/js/utils.js +++ b/js/utils.js @@ -46,9 +46,9 @@ export const parseIni = text => { let section, match; return text.split(/[\r\n]+/g).reduce((data, line) => { if ((match = line.match(PROPERTY_REGEX)) && section != null) { - data[section][match[1].toLowerCase()] = match[2]; + data[section][match[1].trim().toLowerCase()] = match[2]; } else if ((match = line.match(SECTION_REGEX))) { - section = match[1].toLowerCase(); + section = match[1].trim().toLowerCase(); data[section] = {}; } return data; diff --git a/js/utils.test.js b/js/utils.test.js index fc1e595e..33813c5f 100644 --- a/js/utils.test.js +++ b/js/utils.test.js @@ -129,6 +129,19 @@ describe("parseIni", () => { }; expect(actual).toEqual(expected); }); + + it("allows space around =", () => { + const actual = parseIni(` +[foo] +bar = baz +`); + const expected = { + foo: { + bar: "baz" + } + }; + expect(actual).toEqual(expected); + }); }); test("normalize", () => {