refactor: prevent custom field overriding prototype property

This commit is contained in:
Carlos Valente
2026-03-14 07:42:40 +01:00
parent a7a78702b1
commit 2a2554d32a
7 changed files with 36 additions and 9 deletions
@@ -1,5 +1,7 @@
import type { CustomFields } from 'ontime-types';
const objectPrototypeKeys = new Set(Object.getOwnPropertyNames(Object.prototype));
/**
* Transforms an alphanumeric label with spaces into a valid key
*/
@@ -7,6 +9,13 @@ export function customFieldLabelToKey(label: string): string {
return label.trim().replaceAll(' ', '_');
}
/**
* Detects keys that collide with Object prototype properties or methods
*/
export function isObjectPrototypeKey(key: string): boolean {
return objectPrototypeKeys.has(key);
}
/**
* Finds an object key in the CustomFields object that matches the given label
*/