Make WordPress Core

Ticket #39428: 39428.diff

File 39428.diff, 1.6 KB (added by david.binda, 8 years ago)
  • src/wp-includes/class-wp-query.php

     
    21212121                        }
    21222122                        $q['author_name'] = sanitize_title_for_query( $q['author_name'] );
    21232123                        $q['author'] = get_user_by('slug', $q['author_name']);
    2124                         if ( $q['author'] )
     2124                        if ( $q['author'] ) {
    21252125                                $q['author'] = $q['author']->ID;
    2126                         $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint($q['author']) . ')';
     2126                                $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint($q['author']) . ')';
     2127                        } else {
     2128                                $whichauthor .= " AND 1=0";
     2129                        }
    21272130                }
    21282131
    21292132                // MIME-Type stuff for attachment browsing
  • tests/phpunit/tests/query/results.php

     
    704704                $feed_comment = $this->q->next_comment();
    705705                $this->assertEquals( $comment_id, $feed_comment->comment_ID );
    706706        }
     707
     708        /**
     709         * @ticket 39428
     710         */
     711        public function test_nonexisting_author_slug() {
     712                self::factory()->post->create( array( 'post_author' => 1 ) );
     713
     714                $posts = $this->q->query( array( 'author_name' => 'admin' ) );
     715
     716                $this->assertNotEmpty( $posts );
     717                $this->assertNotRegExp( '#AND 1=0#', $this->q->request );
     718
     719                $posts2 = $this->q->query( array( 'author_name' => 'noadmin' ) );
     720               
     721                $this->assertEmpty( $posts2 );
     722                $this->assertRegExp( '#AND 1=0#', $this->q->request );
     723        }
    707724}