[wp-trac] [WordPress Trac] #36126: lastBuildDate in comment feed may not be empty
WordPress Trac
noreply at wordpress.org
Wed Apr 27 22:10:04 UTC 2016
#36126: lastBuildDate in comment feed may not be empty
-------------------------------+------------------------------
Reporter: Cybr | Owner: stevenkword
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Feeds | Version: 4.4.2
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Changes (by Cybr):
* keywords: => reporter-feedback
Comment:
Hi @stevenkword,
Thanks for looking into this.
It's quite complex, and if you feel like it, please read on. Otherwise, go
to the tl;dr section below.
It shouldn't return empty, but it will:
This is because the `$wp_query->is_comment_feed()` is true on the comment
feed, so it will return early with a `max()` statement, which then will
return `null` when no comments are available in the posts.
When I take a look at the function `get_last_build_date_feed()`, I can see
it can make `max()` return false on two occasions.
https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/feed.php?rev=33224 (line 111 and 116).
When listening to these `max()` rules:
1. When comparing two different types, the first one found will be used
(which can be null).
2. Comparing an empty Array will always return false.
And since `max()` is used twice, it has the possibility to return false
twice:
1. Having no posts will result in an empty array (and thus false).
2. Having no comments or posts will result in null on the SQL query, which
is then used as the type setter.
`mysqltodate()` will return false if the 2nd parameter is empty. And when
converting this to a PHP string on echo: `''`.
'''tl;dr:'''
Taking all these variables into account, I believe this bug is achieved by
either removing all approved comments, or having no posts available.
Removing all the approved comments is the easiest way to test this bug.
Having the lastBuildDate output being put into a variable and checking if
it's there before outputting that line will solve this issue.
Please be aware that `if ( ! empty( $var ) )` is three times as slow as
just `if ( $var )`, since we're dealing with scalar types (which we are).
I hope this clears things up!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36126#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list