Skip to content

Commit 6df26e7

Browse files
authored
fix(assertions): 'pattern.indexOf' is not a function (#19009)
In some cases, some CloudFormation templates lead this function to fail. Without looking at the exact templates it's hard to see why, but we can at least be more vigilant against the occurence and check types a bit stronger. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6f270d6 commit 6df26e7

File tree

1 file changed

+8
-3
lines changed
  • packages/@aws-cdk/assertions/lib/private

1 file changed

+8
-3
lines changed

packages/@aws-cdk/assertions/lib/private/cyclic.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ function findExpressionDependencies(obj: any): Set<string> {
7070
} else if (keys.length === 1 && keys[0] === 'Fn::Sub') {
7171
const argument = x[keys[0]];
7272
const pattern = Array.isArray(argument) ? argument[0] : argument;
73-
for (const logId of logicalIdsInSubString(pattern)) {
74-
ret.add(logId);
73+
74+
// pattern should always be a string, but we've encountered some cases in which
75+
// it isn't. Better safeguard.
76+
if (typeof pattern === 'string') {
77+
for (const logId of logicalIdsInSubString(pattern)) {
78+
ret.add(logId);
79+
}
7580
}
7681
const contextDict = Array.isArray(argument) ? argument[1] : undefined;
77-
if (contextDict) {
82+
if (contextDict && typeof contextDict === 'object') {
7883
Object.values(contextDict).forEach(recurse);
7984
}
8085
} else {

0 commit comments

Comments
 (0)