From 6ae95278a4f2ba8ab37f433c9a771d8b60830537 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:46:03 -0700 Subject: [PATCH] Parse profile name with invalid '@' character (#1036) --- .changeset/rude-mice-retire.md | 5 +++++ packages/shared-ini-file-loader/src/parseIni.spec.ts | 11 +++++++++++ packages/shared-ini-file-loader/src/parseIni.ts | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/rude-mice-retire.md diff --git a/.changeset/rude-mice-retire.md b/.changeset/rude-mice-retire.md new file mode 100644 index 00000000000..39156adfd74 --- /dev/null +++ b/.changeset/rude-mice-retire.md @@ -0,0 +1,5 @@ +--- +"@smithy/shared-ini-file-loader": patch +--- + +Parse profile name with invalid '@' character diff --git a/packages/shared-ini-file-loader/src/parseIni.spec.ts b/packages/shared-ini-file-loader/src/parseIni.spec.ts index 273044af7d0..b2f12ed335e 100644 --- a/packages/shared-ini-file-loader/src/parseIni.spec.ts +++ b/packages/shared-ini-file-loader/src/parseIni.spec.ts @@ -58,6 +58,17 @@ describe(parseIni.name, () => { } ); + // Character `@` is not allowed in profile name, but some customers are using it. + // Refs: https://github.com/awslabs/smithy-typescript/issues/1026 + it.each(["-", "_", "@"])("returns data for character '%s' in profile name", (specialChar: string) => { + const mockProfileName = ["profile", "stage"].join(specialChar); + const mockSectionFullName = ["profile", mockProfileName].join(" "); + const mockInput = getMockProfileContent(mockSectionFullName, mockProfileData); + expect(parseIni(mockInput)).toStrictEqual({ + [["profile", mockProfileName].join(CONFIG_PREFIX_SEPARATOR)]: mockProfileData, + }); + }); + it("returns data for two profiles", () => { const mockProfile1 = getMockProfileContent(mockProfileName, mockProfileData); diff --git a/packages/shared-ini-file-loader/src/parseIni.ts b/packages/shared-ini-file-loader/src/parseIni.ts index 1a63a31c052..1cef42ada7f 100644 --- a/packages/shared-ini-file-loader/src/parseIni.ts +++ b/packages/shared-ini-file-loader/src/parseIni.ts @@ -2,7 +2,9 @@ import { IniSectionType, ParsedIniData } from "@smithy/types"; import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; -const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-]+)\2$/; +// Character `@` is not allowed in profile name, but some customers are using it. +// Refs: https://github.com/awslabs/smithy-typescript/issues/1026 +const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@]+)\2$/; const profileNameBlockList = ["__proto__", "profile __proto__"]; export const parseIni = (iniData: string): ParsedIniData => {