Skip to content

Commit 9c75a5f

Browse files
committed
Only validate property value type if we care about the property
1 parent 8e70ae2 commit 9c75a5f

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

lib/init-action.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/feature-flags/properties.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ test.serial(
6464
},
6565
);
6666

67+
test.serial(
68+
"loadPropertiesFromApi does not throw for unexpected value types of unknown properties",
69+
async (t) => {
70+
sinon.stub(api, "getRepositoryProperties").resolves({
71+
headers: {},
72+
status: 200,
73+
url: "",
74+
data: [{ property_name: "not-used-by-us", value: { foo: "bar" } }],
75+
});
76+
const logger = getRunnerLogger(true);
77+
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
78+
await t.notThrowsAsync(
79+
properties.loadPropertiesFromApi(
80+
{
81+
type: util.GitHubVariant.DOTCOM,
82+
},
83+
logger,
84+
mockRepositoryNwo,
85+
),
86+
);
87+
},
88+
);
89+
6790
test.serial(
6891
"loadPropertiesFromApi returns empty object if on GHES",
6992
async (t) => {

src/feature-flags/properties.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ export async function loadPropertiesFromApi(
8585
);
8686
}
8787

88-
if (typeof property.value !== "string") {
89-
throw new Error(
90-
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`,
91-
);
92-
}
93-
9488
if (isKnownPropertyName(property.property_name)) {
89+
// Only validate the type of `value` if this is a property we care about, to avoid throwing
90+
// on unrelated properties that may use representations we do not support.
91+
if (typeof property.value !== "string") {
92+
throw new Error(
93+
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`,
94+
);
95+
}
96+
9597
setProperty(properties, property.property_name, property.value, logger);
9698
}
9799
}

0 commit comments

Comments
 (0)