Skip to content

Commit 5ca90ae

Browse files
fix: handle null value for experiments (#17584)
Fix #17583 **Relevant info** - `option.value` can be `null` - It is always better to use `unknown` instead of `any`, and use type assertion functions as `Array.isArray()` before using/accessing object properties and functions
1 parent 0a26eee commit 5ca90ae

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

site/src/pages/DeploymentSettingsPage/optionValue.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ describe("optionValue", () => {
120120
additionalValues: ["single_tailnet"],
121121
expected: { single_tailnet: true },
122122
},
123+
{
124+
option: {
125+
...defaultOption,
126+
name: "Experiments",
127+
value: null,
128+
},
129+
additionalValues: ["single_tailnet"],
130+
expected: "",
131+
},
123132
{
124133
option: {
125134
...defaultOption,

site/src/pages/DeploymentSettingsPage/optionValue.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export function optionValue(
4040
case "Experiments": {
4141
const experimentMap = additionalValues?.reduce<Record<string, boolean>>(
4242
(acc, v) => {
43-
// biome-ignore lint/suspicious/noExplicitAny: opt.value is any
44-
acc[v] = (option.value as any).includes("*");
43+
const isIncluded = Array.isArray(option.value)
44+
? option.value.includes("*")
45+
: false;
46+
acc[v] = isIncluded;
4547
return acc;
4648
},
4749
{},
@@ -57,10 +59,11 @@ export function optionValue(
5759

5860
// We show all experiments (including unsafe) that are currently enabled on a deployment
5961
// but only show safe experiments that are not.
60-
// biome-ignore lint/suspicious/noExplicitAny: opt.value is any
61-
for (const v of option.value as any) {
62-
if (v !== "*") {
63-
experimentMap[v] = true;
62+
if (Array.isArray(option.value)) {
63+
for (const v of option.value) {
64+
if (v !== "*") {
65+
experimentMap[v] = true;
66+
}
6467
}
6568
}
6669
return experimentMap;

0 commit comments

Comments
 (0)