mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 02:43:50 +00:00
refactor: prevent custom field overriding prototype property
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user