Skip to content

Commit

Permalink
Parse profile name with invalid '@' character (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Oct 13, 2023
1 parent 5bd4682 commit 6ae9527
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rude-mice-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/shared-ini-file-loader": patch
---

Parse profile name with invalid '@' character
11 changes: 11 additions & 0 deletions packages/shared-ini-file-loader/src/parseIni.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion packages/shared-ini-file-loader/src/parseIni.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 6ae9527

Please sign in to comment.