From 04759f206fb8f9b04ddcc226a746dd72fb15bd73 Mon Sep 17 00:00:00 2001 From: Stephen Glass Date: Wed, 31 Jul 2024 19:43:29 -0400 Subject: [PATCH] add null check for review state object check Signed-off-by: Stephen Glass --- .changeset/slow-ligers-drum.md | 5 +++++ .../src/next/components/ReviewState/util.test.ts | 6 +++++- .../src/next/components/ReviewState/util.ts | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/slow-ligers-drum.md diff --git a/.changeset/slow-ligers-drum.md b/.changeset/slow-ligers-drum.md new file mode 100644 index 0000000000..867cc07cee --- /dev/null +++ b/.changeset/slow-ligers-drum.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-react': patch +--- + +Fix null check in `isJsonObject` utility function for scaffolder review state component diff --git a/plugins/scaffolder-react/src/next/components/ReviewState/util.test.ts b/plugins/scaffolder-react/src/next/components/ReviewState/util.test.ts index 9b88ff157e..649d0c3160 100644 --- a/plugins/scaffolder-react/src/next/components/ReviewState/util.test.ts +++ b/plugins/scaffolder-react/src/next/components/ReviewState/util.test.ts @@ -1,5 +1,5 @@ /* - * Copyright 2022 The Backstage Authors + * Copyright 2024 The Backstage Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,10 @@ describe('isJsonObject', () => { expect(isJsonObject(true)).toBe(false); expect(isJsonObject(undefined)).toBe(false); }); + + it('should return false for null values', () => { + expect(isJsonObject(null)).toBe(false); + }); }); describe('getLastKey', () => { diff --git a/plugins/scaffolder-react/src/next/components/ReviewState/util.ts b/plugins/scaffolder-react/src/next/components/ReviewState/util.ts index 49c3b30e7a..d2caf71964 100644 --- a/plugins/scaffolder-react/src/next/components/ReviewState/util.ts +++ b/plugins/scaffolder-react/src/next/components/ReviewState/util.ts @@ -1,5 +1,5 @@ /* - * Copyright 2022 The Backstage Authors + * Copyright 2024 The Backstage Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import { JsonObject, JsonValue } from '@backstage/types'; export function isJsonObject(value?: JsonValue): value is JsonObject { - return typeof value === 'object' && !Array.isArray(value); + return typeof value === 'object' && value !== null && !Array.isArray(value); } // Helper function to get the last part of the key