From 26d76193062541f265ba67f137e3b03bfb5f63f0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 28 Dec 2015 19:06:05 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@36113 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/post.php | 2 +- tests/phpunit/tests/admin/includesPost.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 51ce4c0cf7..c169bd7541 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -687,7 +687,7 @@ function post_exists($title, $content = '', $date = '') { } if ( !empty ( $content ) ) { - $query .= 'AND post_content = %s'; + $query .= ' AND post_content = %s'; $args[] = $post_content; } diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 686cff6242..c9e92f06aa 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -481,6 +481,20 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $this->assertSame( $p, post_exists( $title, $content ) ); } + /** + * @ticket 35246 + */ + public function test_post_exists_should_match_content_with_no_title() { + $title = ''; + $content = 'Foo Bar Baz'; + $p = self::factory()->post->create( array( + 'post_title' => $title, + 'post_content' => $content, + ) ); + + $this->assertSame( $p, post_exists( $title, $content ) ); + } + public function test_post_exists_should_not_match_when_nonempty_content_doesnt_match() { $title = 'Foo Bar'; $content = 'Foo Bar Baz';