Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dot, solidus, percent and colon characters in profile names #1067

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shiny-beans-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/shared-ini-file-loader": patch
---

Allow dot, solidus, percent and colon characters in profile names
23 changes: 15 additions & 8 deletions packages/shared-ini-file-loader/src/parseIni.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ describe(parseIni.name, () => {
// Some characters are not allowed in profile name, but we parse them as customers use them.
// `@` https://github.com/awslabs/smithy-typescript/issues/1026
// `+` https://github.com/aws/aws-sdk-js-v3/issues/5373
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,
});
});
// `.` https://github.com/aws/aws-sdk-js-v3/issues/5449
// `/` https://github.com/awslabs/smithy-typescript/issues/1053
// `%` https://github.com/aws/aws-sdk-java-v2/pull/1538
// `:` https://github.com/aws/aws-sdk-java-v2/pull/1898
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
2 changes: 1 addition & 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,7 @@ import { IniSectionType, ParsedIniData } from "@smithy/types";

import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";

const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+]+)\2$/;
const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
const profileNameBlockList = ["__proto__", "profile __proto__"];

export const parseIni = (iniData: string): ParsedIniData => {
Expand Down
Loading