Skip to content

Commit

Permalink
Mask CurrentVersion literal in Array too
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Feb 23, 2024
1 parent ae04e06 commit 41655e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ exports[`ignore current version 1`] = `
},
"FunctionVersion": {
"Fn::GetAtt": [
"FunctionCurrentVersion4E2B226151c1faf27d0d163dcd41fb04818fca79",
"FunctionCurrentVersion4E2B2261xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Version",
],
},
Expand Down
33 changes: 25 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,32 @@ export const toMatchCdkSnapshot = function (
return propertyMatchers ? matcher(stack, propertyMatchers) : matcher(stack);
};

const maskCurrentVersionRefs = (tree: Record<string, unknown>): void => {
for (const [key, value] of Object.entries(tree)) {
if (key === "Ref" && typeof value === "string") {
const match = currentVersionRegex.exec(value);
if (match) {
tree[key] = `${match[1]}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
const maskCurrentVersionRefs = (tree: unknown): void => {
if (tree == null) {
return;
}
if (Array.isArray(tree)) {
for (let i = 0; i < tree.length; i++) {
const value = tree[i];
if (typeof value === "string") {
const match = currentVersionRegex.exec(value);
if (match) {
tree[i] = `${match[1]}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
}
} else if (typeof value === "object") {
maskCurrentVersionRefs(value);
}
}
} else if (typeof tree === "object") {
for (const [key, value] of Object.entries(tree)) {
if (key === "Ref" && typeof value === "string") {
const match = currentVersionRegex.exec(value);
if (match) {
tree[key] = `${match[1]}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
}
} else if (typeof value === "object") {
maskCurrentVersionRefs(value as Record<string, unknown>);
}
} else if (typeof value === "object" && value !== null) {
maskCurrentVersionRefs(value as Record<string, unknown>);
}
}
};
Expand Down

0 comments on commit 41655e2

Please sign in to comment.