Skip to content

Commit f8bc8b3

Browse files
authored
fix(util-endpoints): return null in parseArn for some empty elements (#3935)
1 parent bbb09f3 commit f8bc8b3

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

packages/util-endpoints/src/lib/aws/parseArn.spec.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ describe(parseArn.name, () => {
7070
expect(parseArn(input)).toEqual(outout);
7171
});
7272

73-
it.each(["some:random:string:separated:by:colons", "arn:aws:too:short"])(
74-
"returns null for invalid arn %s",
75-
(input: string) => {
76-
expect(parseArn(input)).toBeNull();
77-
}
78-
);
73+
it.each([
74+
"arn::s3:us-west-2:123456789012:accesspoint:myendpoint", // partition not present
75+
"arn:aws::us-west-2:123456789012:accesspoint:myendpoint", // service not present
76+
"arn:aws:s3:us-west-2:123456789012:", // resource ID not present
77+
"some:random:string:separated:by:colons",
78+
"arn:aws:too:short",
79+
])("returns null for invalid arn %s", (input: string) => {
80+
expect(parseArn(input)).toBeNull();
81+
});
7982
});

packages/util-endpoints/src/lib/aws/parseArn.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ import { EndpointARN } from "@aws-sdk/types";
88
export const parseArn = (value: string): EndpointARN | null => {
99
const segments = value.split(":");
1010

11-
if (segments.length < 6 || segments[0] !== "arn") return null;
11+
if (segments.length < 6) return null;
1212

13-
const [
14-
,
15-
//Skip "arn" literal
16-
partition,
17-
service,
18-
region,
19-
accountId,
20-
...resourceId
21-
] = segments;
13+
const [arn, partition, service, region, accountId, ...resourceId] = segments;
14+
15+
if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "") return null;
2216

2317
return {
2418
partition,

0 commit comments

Comments
 (0)