-
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
Avoid null for inner block markup value, always return string #59828
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thank you for jumping on this and seeking to resolve so quickly 👍
However, I have concerns about the current state of the change (see comments).
I also think with this type of fix we should write a test to validate the failure and then write code that makes that test go green.
I think we can do that in phpunit/blocks/class-wp-navigation-block-renderer-test.php
.
if ( ! empty( $inner_block_content ) ) { | ||
if ( static::does_block_need_a_list_item_wrapper( $inner_block ) ) { | ||
return '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>'; | ||
} else { | ||
$inner_block_content = ''; | ||
} |
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'm not following this change.
The $inner_block_content
"not empty". So we then check whether it needs a wrapper <li>
. If it doesn't we return an empty string. I'm not sure that makes sense.
To me we need to ensure that the method returns a string as per the @return
. The method should not be returning an empty string just because it doesn't need an <li>
wrapper.
Therefore if $inner_block_content
is empty we should return early with an empty string, and only allow the remainder of the method to execute if there is content.
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.
Yea, I only implemented the text in the issue. Will revise
I did what the issue said would work. The whole function is:
The identified problem is that it sometimes can return null. So the problem is that if there is empty |
In 8f07a37 I updated to always return an empty string if the rendered content is null or empty. |
I know you did. However, I wasn't confident in that solution so I felt I needed to raise that in the review.
I must admit I'd forgotten it worked like that.
This is a much better solution. |
@afercia as the reporter of the Issue are you able to validate and approve? |
I’m curious as to why not use the fix as outlined in #59820
FWIW, I have tested this locally and it does fix the issue. |
@swissspidy thanks for linking to the other PR I assumed it was new and urgent and didn't search. I'll close this one. |
What?
Fixes: #59814
Why?
It's a bug.
How?
Did exactly what the issue says to do.