Make WordPress Core

#64233 closed defect (bug) (fixed)

Command Palette: Use WP_HTML_Processor and WP_HTML_Decoder for menu labels and URLs

Reported by: wildworks Owned by: wildworks
Priority: normal Milestone: 7.0
Component: General Version:
Severity: normal Keywords: has-patch needs-testing dev-reviewed
Cc: Focuses:

Description

There is logic that generates menu labels and menu URLs by referencing the global variables menu and submenu, and registers them as commands. This is working correctly, but there are two areas that could be improved.

Use WP_HTML_Processorfor menu labels

See: https://core.trac.wordpress.org/ticket/64177#comment:10

Use WP_HTML_Decoder for URLs

See: https://core.trac.wordpress.org/ticket/64196#comment:11

Change History (9)

This ticket was mentioned in ​PR #10480 on ​WordPress/wordpress-develop by ​@wildworks.


12 months ago
#1

  • Keywords has-patch added

#2 @wildworks
12 months ago

  • Keywords needs-testing added

​@dmsnell commented on ​PR #10480:


12 months ago
#3

@t-hamano let me know your preferences on this based on my feedback. I’m happy to approve the work if we want to get it in still, understanding that it’s now after the RC1 deadline. I believe that with a couple of sign-offs we can still do so.

​@wildworks commented on ​PR #10480:


12 months ago
#4

Thanks for the feedback!

I tried the latter approach using the WP_HTML_Tag_Processor. What do you think?

By the way, I personally feel there is no need to rush this PR into 6.9 🙂

​@wildworks commented on ​PR #10480:


12 months ago
#5

Thanks for the review, @dmsnell!

Finally, could you review the commit message? I'm concerned that the explanation may not be accurate.

Command Palette: Use WP_HTML_Tag_Processor and WP_HTML_Decoder for menu labels and URLs.

Replace regex-based HTML tag removal with WP_HTML_Tag_Processor to properly extract text nodes from menu labels. This ensures only root-level text nodes are
collected.

Additionally, replace html_entity_decode() with WP_HTML_Decoder::decode_attribute() for URL decoding to use the modern HTML API for consistent attribute decoding.

Follow-up to [61124], [61126], [61127], [61142].

Props: dmsnell, madhavishah01, peterwilsoncc, wildworks.
Fixes #64177, #64196.

​@dmsnell commented on ​PR #10480:


12 months ago
#6

review the commit message?

Generally I just write “use HTML API” rather than noting the specific classes and methods. It might be valuable to tweak the note on “tag removal” since that is what originally led me to misunderstand the problem.

- Command Palette: Use WP_HTML_Tag_Processor and WP_HTML_Decoder for menu labels and URLs.
+ Command Palette: Use HTML API for more reliable menu labels and URLs.

- Replace regex-based HTML tag removal with WP_HTML_Tag_Processor to properly extract text nodes from menu labels. This ensures only root-level text nodes are
collected.
+ Replace regex-based HTML parsing with WP_HTML_Tag_Processor to properly extract text nodes from menu labels. This ensures only root-level text nodes are
collected.

- Additionally, replace html_entity_decode() with WP_HTML_Decoder::decode_attribute() for URL decoding to use the modern HTML API for consistent attribute decoding.
+ Additionally, replace html_entity_decode() with WP_HTML_Decoder::decode_attribute() with the menu URL for consistent attribute decoding.

  Follow-up to [61124], [61126], [61127], [61142].

  Props: dmsnell, madhavishah01, peterwilsoncc, wildworks.
  Fixes #64177, #64196.

I tossed in some minor styling updates in there, which you are free to ignore, but since you asked…

#7 @dmsnell
12 months ago

  • Keywords dev-reviewed added

​@wildworks commented on ​PR #10480:


12 months ago
#8

@dmsnell Thanks for the feedback! I will use that message and commit as per your suggestion.

#9 @wildworks
12 months ago

  • Owner set to wildworks
  • Resolution → fixed
  • Status new → closed

In 61310:

Command Palette: Use HTML API for more reliable menu labels and URLs.

Replace regex-based HTML parsing with WP_HTML_Tag_Processor to properly extract text nodes from menu labels. This ensures only root-level text nodes are
collected.

Additionally, replace html_entity_decode() with WP_HTML_Decoder::decode_attribute() with the menu URL for consistent attribute decoding.

Follow-up to [61124], [61126], [61127], [61142].

Props: dmsnell, madhavishah01, peterwilsoncc, wildworks.
Fixes #64233.

Note: See TracTickets for help on using tickets.