WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#42096 new defect (bug)

`WP_Term_Query` sanitizes `slug` parameter incorrectly

Reported by: boonebgorges Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

At save time, slugs are sanitized for MySQL using sanitize_title(). When constructing a query that is intended to match slugs sanitized in this way, we should use sanitize_title_for_query(). See #19292 [19444].

WP_Term_Query improperly uses sanitize_title() in the query context. https://core.trac.wordpress.org/browser/tags/4.8.2/src/wp-includes/class-wp-term-query.php?marks=495,498#L494 It has always been thus: [30024], [5525]. It should be fixed. Let's get a unit test that describes the bug (see #19292 for sample payload).

Attachments (2)

42096.patch (1.2 KB) - added by tomllobet 3 years ago.
patch with sanitize_title_for_query
42096_tests.patch (2.1 KB) - added by petertoi 3 years ago.
Tests against WP_Term_Query and WP_Query

Download all attachments as: .zip

Change History (7)

@tomllobet
3 years ago

patch with sanitize_title_for_query

#2 @tomllobet
3 years ago

  • Keywords has-patch added; needs-patch removed

We were working on this patch together during a contrib2core meetup with: @petertoi, @pbearne, @benmoody & @jeremyescott. Tests will follow.

This ticket was mentioned in Slack in #core by petertoi. View the logs.


3 years ago

@petertoi
3 years ago

Tests against WP_Term_Query and WP_Query

#4 @petertoi
3 years ago

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

#5 @pbearne
2 years ago

FYI: The recording of the Meetup where we created the patch https://www.youtube.com/watch?v=fDxAFclKlHg

Last edited 2 years ago by pbearne (previous) (diff)
Note: See TracTickets for help on using tickets.