Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#35246 closed defect (bug) (fixed)

post_exists creates SQL-error

Reported by: yetAnotherDaniel Owned by: SergeyBiryukov
Milestone: 4.5 Priority: normal
Severity: normal Version: 2.8
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:


Function post_exists is missing a space:

'AND post_content = %s' // wrong
' AND post_content = %s' // correct

Therefore, it produces an SQL error under the following circumstances:

Create a post with empty title and content '123'.

Run at admin:

add_action( 'admin_init', function() {
        echo post_exists( '', '123' ); exit;

'...You have an error in your SQL syntax...'

I attached a proposal.

Attachments (2)

post_exists.php (866 bytes) - added by yetAnotherDaniel 2 years ago.
new post_exists function
35246.diff (1.2 KB) - added by johnbillion 2 years ago.

Download all attachments as: .zip

Change History (5)

2 years ago

new post_exists function

2 years ago

#1 @johnbillion
2 years ago

  • Component changed from Administration to Posts, Post Types
  • Keywords has-patch has-unit-tests added
  • Milestone changed from Awaiting Review to 4.5
  • Version changed from 4.4 to 2.8

Introduced in [10722].

#2 @johnbillion
2 years ago

Thanks for the report @yetAnotherDaniel! This is indeed a valid bug. I've attached a patch and a unit test. We'll get this fixed in 4.5.

#3 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 36113:

Import: Add a missing space to post_exists().

The lack of space resulted in SQL error when searching for posts by content.

Props yetAnotherDaniel, johnbillion.
Fixes #35246.

Note: See TracTickets for help on using tickets.