Skip to content

Commit

Permalink
Fix array access, add length check and additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Oct 19, 2022
1 parent a691f88 commit 4e3c1f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ export function omitStyle( style, paths, preserveReference = false ) {
if ( path.length > 1 ) {
const [ firstSubpath, ...restPath ] = path;
omitStyle( newStyle[ firstSubpath ], [ restPath ], true );
} else {
delete newStyle[ path ];
} else if ( path.length === 1 ) {
delete newStyle[ path[ 0 ] ];
}
} );

Expand Down
7 changes: 7 additions & 0 deletions packages/block-editor/src/hooks/test/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,11 @@ describe( 'omitStyle', () => {
omitStyle( style3, [ [ 'border', 'radius', 'bottomLeft' ] ] )
).toEqual( style3 );
} );

it( 'should ignore an empty array path', () => {
const style = { typography: {}, '': 'test' };

expect( omitStyle( style, [] ) ).toEqual( style );
expect( omitStyle( style, [ [] ] ) ).toEqual( style );
} );
} );

0 comments on commit 4e3c1f9

Please sign in to comment.