From 95e5ad5a39028500cc3c7b2c5b020dc2afcd4913 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:00:16 +0000 Subject: [PATCH 1/3] Test to populate sub-section in key --- .../src/parseIni.spec.ts | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/shared-ini-file-loader/src/parseIni.spec.ts b/packages/shared-ini-file-loader/src/parseIni.spec.ts index 3ba0ae3db35..ed5db623ea2 100644 --- a/packages/shared-ini-file-loader/src/parseIni.spec.ts +++ b/packages/shared-ini-file-loader/src/parseIni.spec.ts @@ -91,20 +91,33 @@ describe(parseIni.name, () => { }); it("returns data from main section, and not subsection", () => { - const mockMainSettings = { key: "value1" }; - const mockProfileDataWithSubSettings = { ...mockMainSettings, "sub-settings-name": { key: "subValue1" } }; + const mockProfileDataWithSubSettings = { + key: "value", + subSection: { subKey: "subValue" }, + }; const mockInput = getMockProfileContent(mockProfileName, mockProfileDataWithSubSettings); expect(parseIni(mockInput)).toStrictEqual({ - [mockProfileName]: mockMainSettings, + [mockProfileName]: { + key: "value", + "subSection.subKey": "subValue", + }, }); const mockProfileName2 = "mock_profile_name_2"; - const mockMainSettings2 = { key: "value2" }; - const mockProfileDataWithSubSettings2 = { ...mockMainSettings2, "sub-settings-name": { key: "subValue2" } }; + const mockProfileDataWithSubSettings2 = { + key: "value2", + subSection: { subKey: "subValue2" }, + }; const mockInput2 = getMockProfileContent(mockProfileName2, mockProfileDataWithSubSettings2); expect(parseIni(`${mockInput}${mockInput2}`)).toStrictEqual({ - [mockProfileName]: mockMainSettings, - [mockProfileName2]: mockMainSettings2, + [mockProfileName]: { + key: "value", + "subSection.subKey": "subValue", + }, + [mockProfileName2]: { + key: "value2", + "subSection.subKey": "subValue2", + }, }); }); }); From 85b2231a4c0f295bc0abb372e18c2041931b36d4 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:02:07 +0000 Subject: [PATCH 2/3] yarn changeset add --- .changeset/few-panthers-impress.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/few-panthers-impress.md diff --git a/.changeset/few-panthers-impress.md b/.changeset/few-panthers-impress.md new file mode 100644 index 00000000000..4c705bf9219 --- /dev/null +++ b/.changeset/few-panthers-impress.md @@ -0,0 +1,5 @@ +--- +"@smithy/shared-ini-file-loader": minor +--- + +Populate subsection using dot separator in section key when parsing INI files From 5bf84ce760d7a502180d213cfd1a83afee8a063b Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:04:45 +0000 Subject: [PATCH 3/3] Populate subsection using dot separator in section key when parsing INI files --- packages/shared-ini-file-loader/src/parseIni.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/shared-ini-file-loader/src/parseIni.ts b/packages/shared-ini-file-loader/src/parseIni.ts index 933f5bcad31..f578307320e 100644 --- a/packages/shared-ini-file-loader/src/parseIni.ts +++ b/packages/shared-ini-file-loader/src/parseIni.ts @@ -26,10 +26,10 @@ export const parseIni = (iniData: string): ParsedIniData => { ]; if (value === "") { currentSubSection = name; - } else if (currentSubSection === undefined) { - // ToDo: populate subsection in future PR, when IniSection is updated to support subsections. + } else { map[currentSection] = map[currentSection] || {}; - map[currentSection][name] = value; + const key = currentSubSection ? `${currentSubSection}.${name}` : name; + map[currentSection][key] = value; } } }