Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#41837 new defect (bug)

WP_User_Query can generate negative offset in the LIMIT clause

Reported by: birgire's profile birgire Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.4
Component: Users Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by SergeyBiryukov)

The paged argument in WP_User_Query was introduced in #34531

There's a problem with the paged as 0 case.

There's a similar ticket for WP_Comment_Query: #41826

Example:

When paged is 0 and number is 2, WP_User_Query generates the LIMIT clause:

LIMIT -2, 2 

instead of

LIMIT 0, 2 

According to the MySQL documentation, the offset in the LIMIT clause shouldn't be negative:

https://dev.mysql.com/doc/refman/5.7/en/select.html

I think we should handle it in the same way as in WP_Query, where the 0 case is the same as 1.

Attachments (1)

41837.patch (1.8 KB) - added by birgire 7 years ago.

Download all attachments as: .zip

Change History (3)

@birgire
7 years ago

#1 @SergeyBiryukov
7 years ago

  • Component changed from Query to Users
  • Description modified (diff)

#2 @birgire
7 years ago

  • Keywords has-patch has-unit-tests added

The 0 case is now same as 1.

Here we focus on the calculated offset in the LIMIT clause.

The pagination setup is made similar to the one in the other query classes.

Included is a test for this case.

@SergeyBiryukov Thanks for fixing the typo in the description

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