Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#35246 closed defect (bug) (fixed)

post_exists creates SQL-error

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

Description

Function post_exists is missing a space:

<?php
'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:

<?php
add_action( 'admin_init', function() {
        echo post_exists( '', '123' ); exit;
});

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

I attached a proposal.

Attachments (2)

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

Download all attachments as: .zip

Change History (5)

@yetAnotherDaniel
11 years ago

new post_exists function

@johnbillion
11 years ago

#1 @johnbillion
11 years ago

  • Component AdministrationPosts, Post Types
  • Keywords has-patch has-unit-tests added
  • Milestone Awaiting Review4.5
  • Version 4.42.8

Introduced in [10722].

#2 @johnbillion
11 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
11 years ago

  • Owner set to SergeyBiryukov
  • Resolutionfixed
  • Status newclosed

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.