WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#41826 new defect (bug)

WP_Comment_Query can generate negative offset in LIMIT clause

Reported by: birgire Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: Comments Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

The paged argument in WP_Comment_Query was introduced in #38268

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

Example:

When the paged is 0 and number is 2, WP_Comment_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 treated as the default, that is 1.

Attachments (2)

41826.patch (1.5 KB) - added by birgire 3 months ago.
41826.2.patch (1.8 KB) - added by birgire 3 months ago.

Download all attachments as: .zip

Change History (5)

@birgire
3 months ago

#1 @birgire
3 months ago

  • Keywords has-patch has-unit-tests added

The 0 case is now same as 1.

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

Included is a test for this case.

Last edited 3 months ago by birgire (previous) (diff)

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


3 months ago

#3 @SergeyBiryukov
3 months ago

  • Component changed from Query to Comments

@birgire
3 months ago

Note: See TracTickets for help on using tickets.