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:
kolaente 2026-04-15 13:05:40 +02:00 committed by kolaente
parent dd83e0d42b
commit d09ef36bd4
3 changed files with 4 additions and 4 deletions

View File

@ -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
}

View File

@ -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]
}

View File

@ -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
}