Skip to content

Commit

Permalink
Administration: Remove redundant type casting in `WP_List_Table::sear…
Browse files Browse the repository at this point in the history
…ch_box()`.

Scalar values passed to `esc_attr()` are already converted internally to a string via both `wp_check_invalid_utf8()` and `_wp_specialchars()`.

Includes adding `@covers` tags for unit tests.

Follow-up to [58379].

See #58379.

git-svn-id: https://develop.svn.wordpress.org/trunk@58389 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jun 11, 2024
1 parent b215c59 commit adeb3ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/wp-admin/includes/class-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,6 @@ public function search_box( $text, $input_id ) {
if ( ! empty( $_REQUEST['orderby'] ) ) {
if ( is_array( $_REQUEST['orderby'] ) ) {
foreach ( $_REQUEST['orderby'] as $key => $value ) {
/*
* Orderby can be either an associative array or non-associative array.
* In the latter case, this makes sure the key is a string before calling esc_attr().
*/
$key = (string) $key;
echo '<input type="hidden" name="orderby[' . esc_attr( $key ) . ']" value="' . esc_attr( $value ) . '" />';
}
} else {
Expand Down
16 changes: 11 additions & 5 deletions tests/phpunit/tests/admin/wpListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function data_should_only_add_primary_column_when_needed() {
}

/**
* Tests the "get_views_links()" method.
* Tests the `WP_List_Table::get_views_links()` method.
*
* @ticket 42066
*
Expand Down Expand Up @@ -255,7 +255,7 @@ public function data_get_views_links() {
}

/**
* Tests that "get_views_links()" throws a _doing_it_wrong().
* Tests that `WP_List_Table::get_views_links()` throws a `_doing_it_wrong()`.
*
* @ticket 42066
*
Expand Down Expand Up @@ -523,9 +523,11 @@ public function data_compat_fields() {
}

/**
* Tests that "search_box()" works correctly with an orderby array with multiple values.
* Tests that `WP_List_Table::search_box()` works correctly with an `orderby` array with multiple values.
*
* @ticket 59494
*
* @covers WP_List_Table::search_box()
*/
public function test_search_box_working_with_array_of_orderby_multiple_values() {
$_REQUEST['s'] = 'search term';
Expand All @@ -544,9 +546,11 @@ public function test_search_box_working_with_array_of_orderby_multiple_values()
}

/**
* Tests that "search_box()" works correctly with an orderby array with a single value.
* Tests that `WP_List_Table::search_box()` works correctly with an `orderby` array with a single value.
*
* @ticket 59494
*
* @covers WP_List_Table::search_box()
*/
public function test_search_box_working_with_array_of_orderby_single_value() {
// Test with one 'orderby' element.
Expand All @@ -563,9 +567,11 @@ public function test_search_box_working_with_array_of_orderby_single_value() {
}

/**
* Tests that "search_box()" works correctly with orderby set to a string.
* Tests that `WP_List_Table::search_box()` works correctly with `orderby` set to a string.
*
* @ticket 59494
*
* @covers WP_List_Table::search_box()
*/
public function test_search_box_works_with_orderby_string() {
// Test with one 'orderby' element.
Expand Down

0 comments on commit adeb3ec

Please sign in to comment.