Fix document title html entities#74027
Conversation
| showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ), | ||
| documentLabel: | ||
| // translators: Default label for the Document in the Block Breadcrumb. | ||
| postTypeLabel || _x( 'Document', 'noun, breadcrumb' ), |
There was a problem hiding this comment.
This fallback to 'Document' was duplicating what the BlockBreadcrumb component already does, so I've removed it.
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jdoubleu. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
| const rootLabel = rootLabelText || __( 'Document' ); | ||
|
|
||
| // translators: Default label for the Document in the Block Breadcrumb. | ||
| const rootLabel = rootLabelText || _x( 'Document', 'noun, breadcrumb' ); |
There was a problem hiding this comment.
Updated this to match the fallback translation used elsewhere.
|
Size Change: -217 B (-0.01%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 14e6296. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20262315365
|
ramonjd
left a comment
There was a problem hiding this comment.
Nice work, thanks for fixing this old bug!
LGTM in the sidebar and doc breadcrumb.
Here's the sidebar:
| Before | After |
|---|---|
![]() |
![]() |
Optional, I noticed that the sidebar title's button element has white-space: nowrap;, which keeps the title on one line despite the soft hyphen. The breadcrumb button (.block-editor-block-breadcrumb__button) doesn't have white-space: nowrap;:
I guess this can be seen in two ways:
white-space: nowrap;prevents the soft hyphen from working, ORwhite-space: nowrap;enforces a one-line rule.
Not sure which is preferred, but since it's on trunk and an edge case, I don't think folks are going to lose any sleep over it.
| rootLabelText={ decodeEntities( postTypeLabel ) } | ||
| /> |
There was a problem hiding this comment.
Should editor-interface/index.js explicitly check for postTypeLabel before calling decodeEntities to match sidebar/header.js?
There was a problem hiding this comment.
👍 I've pushed some code to do that.
decodeEntities does handle null or undefined values, but I guess it makes no sense to call it with nothing.
| mode === 'visual' && ( | ||
| <BlockBreadcrumb rootLabelText={ documentLabel } /> | ||
| <BlockBreadcrumb | ||
| rootLabelText={ decodeEntities( postTypeLabel ) } |
There was a problem hiding this comment.
Wouldn't it make sense to decode this label in the BlockBreadcrumb component and before the actual value is rendered?
My thinking here is similar to escaping data: you want to escape when you echo, not before. Ref: https://developer.wordpress.org/apis/security/escaping/#escaping-functions
There was a problem hiding this comment.
Because BlockBreadcrumb is a general purpose component that's exported, someone might be using it with a rootLabelText value that doesn't need to be decoded, so my thinking is that it's best not to always decode the value.
Might as well fix this too, pushed a |


What?
Fixes #28558
When registering a postType, devs might add html entities in the postType label. These were being rendered verbatim in two places in the UI - the document tab title and the block breadcrumbs. The 'Address Bar' area also shows the postType label, but already handles decoding the entities.
How?
This PR uses decodeEntities to convert any entities.
Testing Instructions
Expected: The post title doesn't render HTML entities in the Block Breadcrumbs (in the editor footer) or the document tab title (in the inspector)
In trunk:
­is rendered in the textlabelvalue for the post type to an empty string''.Screenshots or screencast
Before
After