You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ampersand's in the Navigation block are converted to u0026 #59516
Adding ampersands '&' to the label field of a link (page & custom) in the Navigation block converts it to u0026, which displays on the frontend and backend once refreshed.
Adding to 6.5 but let's test with 6.4.3 to ensure this is related to the 6.5 release. If no one beats me to it, I'll do that tomorrow (@fabiankaegy in case you can!)
Oh, I'm not sure I read that correctly. Doesn't that mean that wp_update_post expects that the $postarr argument has already been escaped if it's an array, and escapes it itself if it's an object? If so, then I think that's what we want, in order to avoid escaping twice, no? 🤔
Yeah. My current theory is that this is happening somewhere along the way between parse_blocks and traverse_and_serialize_block.
The fact that News & Events becomes News u0026amp; Evens indicates that there are some transforms that work okay, probably News & Events -> News & Events->News \\0026amp; Events ✅
But somehow, the double backslash is then stripped: News \\0026amp; Events -> News 0026amp; Events ❌
I'll have to wrap up for today; I'll continue working on it tomorrow. In the meantime, feel free to continue investigating and push commits to that PR 😊
This problem appears to be not limited to the Navigation Link block. At least it also happens with Search and Home Link blocks. However, it doesn't seem to occur on the Button block.
This problem appears to be not limited to the Navigation Link block. At least it also happens with Search and Home Link blocks. However, it doesn't seem to occur on the Button block.
Yeah, I suspect this is because button text is not stored in the blocks attribute values where as the other text/labels in the blocks you have mentioned are. It's the process of serializing/parsing these attributes which is where things go a bit wild.
@dmsnell I know you have specific expertise in these types of problems and may well also be aware of changes in Core that could have caused this. Can you help shed any light on this?
Thanks for asking @getdave. I had no ideas other than I wish we were done rewriting Core with the HTML API. I'm hoping to eliminate these kinds of issues, which creep up to frequently. It took me a lot of time and frustration to figure out a way to write <![CDATA[test]]> in the Dev Notes for the HTML API, and the solution involves some carefully-placed zero-width spaces.
The problem is almost certainly inside of wp_kses_normalize_entities() given the chain through u0026amp;, but there are many roads to and through there.
Activity
annezazu commentedon Mar 4, 2024
Adding to 6.5 but let's test with 6.4.3 to ensure this is related to the 6.5 release. If no one beats me to it, I'll do that tomorrow (@fabiankaegy in case you can!)
fabiankaegy commentedon Mar 4, 2024
I just tested this and was able to verify that it is not happening in 6.4.3 but is happening on 6.5 Beta 3.
fabiankaegy commentedon Mar 4, 2024
@getdave Tagging you here as one of the maintainers of the Navigation Block
getdave commentedon Mar 4, 2024
I can replicate. Likely to due to how label is escaped in the
core/navigation-linkblock.I'm going to recommend that whatever fix we implement we add test coverage for in a follow up as similar issues have occurred a few times now.
getdave commentedon Mar 4, 2024
Testing I found the following is stored in the database
Notice the
News u0026amp; Events.I tested with removing the escaping in
gutenberg/packages/block-library/src/navigation-link/update-attributes.js
Lines 75 to 77 in 8c5d40b
...and it does change the conversion to entities.
7 remaining items
t-hamano commentedon Mar 4, 2024
If I'm testing correctly, this problem first appeared on the backport for Beta2. Commit hash
c84cddbon GitHub.WordPress/wordpress-develop@c84cddb
This problem does not seem to occur if you check out the previous commit (
18b21c3).t-hamano commentedon Mar 4, 2024
wp_update_post()is being executed here, is it because it is escaped in case of an array?https://developer.wordpress.org/reference/functions/wp_update_post/#parameters
ockham commentedon Mar 4, 2024
Ohh, that looks like it could be the reason!
ockham commentedon Mar 4, 2024
Oh, I'm not sure I read that correctly. Doesn't that mean that
wp_update_postexpects that the$postarrargument has already been escaped if it's an array, and escapes it itself if it's an object? If so, then I think that's what we want, in order to avoid escaping twice, no? 🤔getdave commentedon Mar 4, 2024
https://developer.wordpress.org/reference/functions/wp_update_post/
t-hamano commentedon Mar 4, 2024
Hmm, maybe
wp_update_postitself is not the fundamental problem...ockham commentedon Mar 4, 2024
Yeah. My current theory is that this is happening somewhere along the way between
parse_blocksandtraverse_and_serialize_block.The fact that
News & EventsbecomesNews u0026amp; Evensindicates that there are some transforms that work okay, probablyNews & Events->News & Events->News \\0026amp; Events✅But somehow, the double backslash is then stripped:
News \\0026amp; Events->News 0026amp; Events❌I haven't yet been able to find out where.
(Edit: Backslash, not slash.)
ockham commentedon Mar 4, 2024
Hmm, looks like we have test coverage for parsing/serialization of backslashes in attribute values though: https://github.com/WordPress/wordpress-develop/blob/0f45a3c9fc10d1abf68ec9e201e6113815cdbb34/tests/phpunit/tests/blocks/serialize.php#L44-L45
(Edit: Backslashes, not slashes.)
ockham commentedon Mar 4, 2024
I'll try creating a minimal unit test for this so we can debug more easily.
ockham commentedon Mar 4, 2024
#59561
I'll have to wrap up for today; I'll continue working on it tomorrow. In the meantime, feel free to continue investigating and push commits to that PR 😊
t-hamano commentedon Mar 5, 2024
This problem appears to be not limited to the Navigation Link block. At least it also happens with Search and Home Link blocks. However, it doesn't seem to occur on the Button block.
95cce3c9abab7bd69d5766f732b93ebe.mp4
tjcafferkey commentedon Mar 5, 2024
Yeah, I suspect this is because button text is not stored in the blocks attribute values where as the other text/labels in the blocks you have mentioned are. It's the process of serializing/parsing these attributes which is where things go a bit wild.
dmsnell commentedon Mar 5, 2024
Thanks for asking @getdave. I had no ideas other than I wish we were done rewriting Core with the HTML API. I'm hoping to eliminate these kinds of issues, which creep up to frequently. It took me a lot of time and frustration to figure out a way to write
<![CDATA[test]]>in the Dev Notes for the HTML API, and the solution involves some carefully-placed zero-width spaces.The problem is almost certainly inside of
wp_kses_normalize_entities()given the chain throughu0026amp;, but there are many roads to and through there.