-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
File block: Remove anchor tag when copy pasting to file name #56508
Conversation
Size Change: +345 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
downloadButtonText: removeAnchorTag( | ||
_x( 'Download', 'button label' ) | ||
), |
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.
Although this would not be necessary in practice, it allows for the possibility that the translated text has anchors.
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.
This translated text shouldn't have HTML in it, and React shouldn't render it anyway. So I agree this is unnecessary.
We can't strip every possible translation.
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.
Indeed. Updated with 0bf95cd 👍
Flaky tests detected in 0bf95cd. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6982994376
|
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.
Nice fix @t-hamano 👍
✅ Everything tests as advertised
✅ Anchor tags are correctly stripped out
✅ Block isn't broken and renders as expected on the frontend
Do you think it is worth extracting the removeAnchorTag
into a helper function that can be shared across blocks?
LGTM 🚢
Thanks for the review, @aaronrobertshaw!
That makes sense. Updated 👍 |
* File block: Remove anchor tag when copy pasting to file name * Don't strip default button text * eEtract removeAnchorTag() function
Fixes #54820
Follow-up #29273
What?
This PR fixes an issue where if content containing an anchor is pasted into the filename of a file block, validation will fail and the block will become corrupted.
Why?
This block's file name and button are both anchor elements, so you cannot put an anchor element inside them. In #29273, this issue was fixed for the download button, but the same fix should be applied for the file name as well.
How?
I also added a process to remove anchors in the file name. At the same time, I changed the function name to something easier to understand, and changed the function to purely processing strings without executing
setAttributes()
inside the function.Testing Instructions
Screenshots or screencast
132a90c04813d9e5778b77e5a201d2a7.mp4