Skip to content

Commit

Permalink
fix(assertions): 'pattern.indexOf' is not a function (aws#19009)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
rix0rrr authored and TikiTDO committed Feb 21, 2022
1 parent c03d19a commit 9d171dc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/@aws-cdk/assertions/lib/private/cyclic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ function findExpressionDependencies(obj: any): Set<string> {
} else if (keys.length === 1 && keys[0] === 'Fn::Sub') {
const argument = x[keys[0]];
const pattern = Array.isArray(argument) ? argument[0] : argument;
for (const logId of logicalIdsInSubString(pattern)) {
ret.add(logId);

// pattern should always be a string, but we've encountered some cases in which
// it isn't. Better safeguard.
if (typeof pattern === 'string') {
for (const logId of logicalIdsInSubString(pattern)) {
ret.add(logId);
}
}
const contextDict = Array.isArray(argument) ? argument[1] : undefined;
if (contextDict) {
if (contextDict && typeof contextDict === 'object') {
Object.values(contextDict).forEach(recurse);
}
} else {
Expand Down

0 comments on commit 9d171dc

Please sign in to comment.