Skip to content

Commit

Permalink
Fix the removePropertyFromObject function throws an error if the obje…
Browse files Browse the repository at this point in the history
…ct is null (#60831)

Co-authored-by: arthur791004 <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
3 people authored Apr 17, 2024
1 parent a6e8b68 commit f5ee54f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,10 @@ describe( 'removePropertyFromObject', () => {
expect( removePropertyFromObject( object, 'color' ) ).toEqual( object );
} );

it( 'should return with null', () => {
expect( removePropertyFromObject( null, 'color' ) ).toEqual( null );
} );

it( 'should remove the specified property from the object', () => {
expect(
removePropertyFromObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export function removePropertyFromObject( object, property ) {
return object;
}

if ( typeof object !== 'object' || ! Object.keys( object ).length ) {
if (
typeof object !== 'object' ||
! object ||
! Object.keys( object ).length
) {
return object;
}

Expand Down

0 comments on commit f5ee54f

Please sign in to comment.