Skip to content

Commit c6a5303

Browse files
zhangLei99586vincentkoc
authored andcommitted
fix(browser): guard setDeep against empty keys array
When keys is empty, keys[keys.length - 1] returns undefined, and the previous ?? fallback would silently create a property with an empty string key on the target object. Add an early return so empty keys are a no-op instead of silently polluting the object.
1 parent 3558391 commit c6a5303

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

extensions/browser/src/browser/chrome.profile-decoration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ function readNestedRecord(root: unknown, key: string): Record<string, unknown> |
3838
}
3939

4040
function setDeep(obj: Record<string, unknown>, keys: string[], value: unknown) {
41+
if (keys.length === 0) {
42+
return;
43+
}
4144
let node: Record<string, unknown> = obj;
4245
for (const key of keys.slice(0, -1)) {
4346
const next = node[key];
@@ -46,7 +49,7 @@ function setDeep(obj: Record<string, unknown>, keys: string[], value: unknown) {
4649
}
4750
node = node[key] as Record<string, unknown>;
4851
}
49-
node[keys[keys.length - 1] ?? ""] = value;
52+
node[keys[keys.length - 1]] = value;
5053
}
5154

5255
function parseHexRgbToSignedArgbInt(hex: string): number | null {

0 commit comments

Comments
 (0)