mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
refactor: prevent custom field overriding prototype property
This commit is contained in:
@@ -61,7 +61,7 @@ export { checkRegex, regex } from './src/regex-utils/checkRegex.js';
|
||||
export { isColourHex } from './src/regex-utils/isColourHex.js';
|
||||
export { splitWhitespace } from './src/regex-utils/splitWhitespace.js';
|
||||
|
||||
export { customFieldLabelToKey, customKeyFromLabel } from './src/customField-utils/customFieldUtils.js';
|
||||
export { customFieldLabelToKey, customKeyFromLabel, isObjectPrototypeKey } from './src/customField-utils/customFieldUtils.js';
|
||||
|
||||
// helpers from externals
|
||||
export { deepmerge } from './src/externals/deepmerge.js';
|
||||
|
||||
@@ -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