Make WordPress Core

Opened 5 months ago

Closed 5 months ago

#64196 closed defect (bug) (fixed)

Command Palette: Refactor enqueue function to remove regex.

Reported by: cbravobernal's profile cbravobernal Owned by: davidbaumwald's profile davidbaumwald
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch needs-testing
Focuses: Cc:

Description

The wp_enqueue_command_palette_assets() function uses REGEX to remove all HTML tags and their contents from the menu items, so that it only display text.

It was using REGEX for it, and can be replaced with the Tag Processor.

Attachments (1)

command-palette-search-plugin.png (14.3 KB) - added by wildworks 5 months ago.
Search for "plugins". The number zero will be displayed visually.

Download all attachments as: .zip

Change History (18)

This ticket was mentioned in PR #10461 on WordPress/wordpress-develop by @cbravobernal.


5 months ago
#1

  • Keywords has-patch added

Refactors the code on the command palette enqueue function to strip the HTML by using the Tag Processor instead of a couple of regex functions.

Proposed by @dmsnell . Props to him.

Trac ticket: https://core.trac.wordpress.org/ticket/64196

#2 @davidbaumwald
5 months ago

  • Owner set to davidbaumwald
  • Resolution set to fixed
  • Status changed from new to closed

In 61126:

Command Palette: Use HTML_Tag_Processor to get the menu label when enqueueing assets, not regex.

HTML_Tag_Processor is more better.

Follow-up to [61022].

Props dmsnell, cbravobernal.
Fixes #64196.

#3 @davidbaumwald
5 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Small initialization bug. Follow-up commit incoming.

#4 @davidbaumwald
5 months ago

In 61127:

Command Palette: Ensure $menu_label is initialized before using it.

Unprops davidbaumwald.

Follow-up to [61126].

Props cbravobernal.
See #64196.

#5 @davidbaumwald
5 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

#6 @wildworks
5 months ago

I don't think we can simply replace REGEX with HTML_Tag_Processor. The menu may contain the 0 that are visually hidden. See https://github.com/WordPress/gutenberg/pull/71476#discussion_r2318390285 for more details.

@wildworks
5 months ago

Search for "plugins". The number zero will be displayed visually.

#7 @wildworks
5 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#8 @tusharaddweb
5 months ago

I test this in my local setup but it still persist

Go through the below image link

https://postimg.cc/D41TLnZK

Last edited 5 months ago by tusharaddweb (previous) (diff)

#9 @cbravobernal
5 months ago

I'll revert the commits as soon as possible. Thanks @wildworks for pointing it out and @tusharaddweb for confirming.

#10 @cbravobernal
5 months ago

In 61142:

Command Palette: Revert Use HTLM_Tag_Processor to get the menu label when enqueueing assets.

Reverts [61126] and [61127], which introduced a bug where the command palette is not stripping numbers. HTML_Tag_Processor cannot replace the REGEX yet.

Unprops cbravobernal.

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

Props wildworks, tusharaddweb.
See #64196.

#11 @dmsnell
5 months ago

If the issue is removing content inside of the HTML tags we can still do that. In reading the PCRE pattern and the comment above it, I misunderstood the purpose of the existing code. Thanks for highlighting that @wildworks.

The fix is not much different than the proposed HTML API code. All we have to do is track depth based on opening and closing tags, or use WP_HTML_Processor and rely on its get_depth() report.

That will still resolve a number of issues with the PCRE approach, including misparses, handling HTML void elements like HR, and leaving potentially-encoded labels in place instead of decoding them.

#12 @madhavishah01
5 months ago

Tested this locally and found Theme : 0

Kindly refer below screenshot:-
https://postimg.cc/DW6F8JLL

#13 @wildworks
5 months ago

The fix is not much different than the proposed HTML API code. All we have to do is track depth based on opening and closing tags, or use WP_HTML_Processor and rely on its get_depth() report.

@dmsnell Thank you for telling me this! I'll try this approach tomorrow.

I might address this feedback in the same pull request as well: #64177

#14 @wildworks
5 months ago

I have submitted a PR: https://github.com/WordPress/wordpress-develop/pull/10480/

This PR addresses both this ticket and #64177.

#15 @wildworks
5 months ago

  • Keywords needs-testing added

#16 @wildworks
5 months ago

  • Milestone changed from 6.9 to 7.0

There's less than an hour until the RC1 commit freeze. I'm not entirely confident about PR 10480, so let's punt this ticket to 7.0.

If this patch needs to be included in version 6.9, let's reconsider it.

#17 @wildworks
5 months ago

  • Milestone changed from 7.0 to 6.9
  • Resolution set to fixed
  • Status changed from reopened to closed

I have opened a new #64233 to address the new issue, so I will close this ticket.

Note: See TracTickets for help on using tickets.