fix(frontend): guard Object.keys against null in refactored helpers
typeof null === 'object', so null slipped past the type guards in objectToCamelCase/objectToSnakeCase/prepareParams. The original for...in loops silently iterated nothing on null; Object.keys(null) throws. Also guard saveCollapsedBucketState where state[projectId] may be undefined.
This commit is contained in:
parent
dd83e0d42b
commit
d09ef36bd4
|
|
@ -7,7 +7,7 @@ import {camelCase, snakeCase} from 'change-case'
|
|||
export function objectToCamelCase(object: Record<string, any>) {
|
||||
|
||||
// When calling recursively, this can be called without being and object or array in which case we just return the value
|
||||
if (typeof object !== 'object') {
|
||||
if (typeof object !== 'object' || object === null) {
|
||||
return object
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ export function objectToCamelCase(object: Record<string, any>) {
|
|||
export function objectToSnakeCase(object: Record<string, any>) {
|
||||
|
||||
// When calling recursively, this can be called without being and object or array in which case we just return the value
|
||||
if (typeof object !== 'object') {
|
||||
if (typeof object !== 'object' || object === null) {
|
||||
return object
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export const saveCollapsedBucketState = (
|
|||
) => {
|
||||
const state = getAllState()
|
||||
state[projectId] = collapsedBuckets
|
||||
for (const bucketId of Object.keys(state[projectId])) {
|
||||
for (const bucketId of Object.keys(state[projectId] ?? {})) {
|
||||
if (!state[projectId][bucketId]) {
|
||||
delete state[projectId][bucketId]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ function convertObject(o: unknown) {
|
|||
}
|
||||
|
||||
function prepareParams(params: Record<string, unknown | unknown[]>) {
|
||||
if (typeof params !== 'object') {
|
||||
if (typeof params !== 'object' || params === null) {
|
||||
return params
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue