-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Footnotes: Fix recursion into updating attributes when attributes is not an object #53257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,15 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) { | |
); | ||
|
||
function updateAttributes( attributes ) { | ||
// Only attempt to update attributes, if attributes is an object. | ||
if ( | ||
! attributes || | ||
Array.isArray( attributes ) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will attributes ever be an Array? Edit: okay, I just re-read the PR description. Ignore me. |
||
typeof attributes !== 'object' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just had to double check for my own benefit: this could catch 👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the extra checking! The problem for
Then, if we remove the Before / after: In practice, I think it's fairly unlikely that there'll be blocks out in the wild affected by it, but good to catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for taking the time to double check! |
||
) { | ||
return attributes; | ||
} | ||
|
||
attributes = { ...attributes }; | ||
|
||
for ( const key in attributes ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this falsy check is required because
typeof null
equalsobject
so this catches if somehow this function is called withnull
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this yet, but just staring at it makes me think it's a safe change regardless since we're destructuring
attributes
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, one of the things that tripped me up when looking at this function is that when passed anything other than an object, the destructuring winds up converting (or attempting to convert) to an object.
Hopefully it's a fairly safe-ish change! The thing that took me the longest was testing it out in a custom block 😅
Thanks for taking a look!