Make WordPress Core

Opened 5 months ago

Closed 3 months ago

#63633 closed defect (bug) (fixed)

Post Types with numeric characters in the slug are not searchable within the nav menu

Reported by: kshaner's profile kshaner Owned by: westonruter's profile westonruter
Milestone: 6.9 Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

When a post type is registered, the slug is run through sanitize_key.

The docblock for sanitize_key:

Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes, and underscores are allowed.

When a post type is registered with a numeric character, the function _wp_ajax_menu_quick_search contains a regex that tries to match the post type from the request payload $_POSTtype? which contains a payload formatted like: quick-search-posttype-post or quick-search-posttype-page.

However when a numeric character is in the post type slug, the regex that validates the post type does not allow numeric characters.

The current call is:

preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) )

To match the allowed formats of sanitize_key, this regex should be modified to:

preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z0-9_-]*\b)/', $type, $matches ) )

Change History (8)

This ticket was mentioned in PR #9101 on WordPress/wordpress-develop by kshaner.


5 months ago
#1

  • Keywords has-patch added

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


5 months ago

#3 @oglekler
5 months ago

  • Keywords needs-testing added
  • Severity changed from major to normal
  • Version 6.8 deleted

This ticket needs a reproduction report and testing.

@kshaner commented on PR #9101:


5 months ago
#4

@mindctrl Unit test added! Confirmed the test failed against trunk and passed on this branch.

#5 @mindctrl
3 months ago

  • Keywords has-unit-tests added; needs-testing removed

@kshaner nice find. I've tested your patch and confirmed it fixes the issue.

Here what I did:

  • activated a non-block theme such as Twenty Twelve
  • confirmed this is a bug in trunk with the classic menu editor
  • registered a custom post type with the slug test_123
  • created a new post of the test_123 type
  • went to Appearance > Menus
  • clicked Screen Options at top right and enabled the "Test 123" post type
  • expanded the Test 123 panel in the menu editor
  • clicked Search
  • typed in some characters from the new post and saw the results

#6 @westonruter
3 months ago

  • Milestone changed from Awaiting Review to 6.9
  • Owner set to westonruter
  • Status changed from new to accepted

#7 @westonruter
3 months ago

  • Version set to 3.0

#8 @westonruter
3 months ago

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

In 60775:

Menus: Fix searchability of post types which contain numeric characters.

The regular expression needs to correspond to how a post type slug is sanitized by sanitize_key() in register_post_type().

Props kshaner, mindctrl, oglekler.
Fixes #63633.

Note: See TracTickets for help on using tickets.