Make WordPress Core


Ignore:
Timestamp:
10/10/2023 11:20:28 AM (14 months ago)
Author:
SergeyBiryukov
Message:

Query: Ensure that the page parameter is scalar in WP_Query::get_posts().

The page query var only accepts a scalar value and passes the value through functions that assume a scalar value.

Adding an extra guard condition does not affect its functionality but does avoid a PHP fatal error for trim() when a non-scalar value such as an array is passed.

Follow-up to [2535], [53891].

Props brookedot, rlmc, mukesh27, SergeyBiryukov.
Fixes #56558.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/invalidQueries.php

    r52577 r56815  
    160160        $this->assertCount( 1, $query->posts );
    161161    }
     162
     163    /**
     164     * Ensure a non-scalar page parameter does not throw a fatal error for trim().
     165     *
     166     * @ticket 56558
     167     * @covers WP_Query::get_posts
     168     */
     169    public function test_non_scalar_page_value() {
     170        $query = new WP_Query(
     171            array(
     172                'page' => array( 1, 2, 3 ),
     173            )
     174        );
     175
     176        $this->assertSame( 0, $query->query_vars['page'] );
     177    }
    162178}
Note: See TracChangeset for help on using the changeset viewer.