WordPress.org

Make WordPress Core

#19733 closed defect (bug) (fixed)

XML-RPC returns invalid dates if the date is zero

Reported by: koke Owned by: westi
Priority: normal Milestone: 3.4
Component: XML-RPC Version: 3.3
Severity: normal Keywords: has-patch mobile needs-unit-tests
Cc: ercoli@…, marko@…, max@…

Description

When a post has a 'pending' status, post_date_gmt is set to 0000-00-00 00:00:00 as a marker to update post_date when it's saved (see #5698).

mysql2date then proceeds to turn that date into a negative one, and IXR_Date destroys the thing a bit more, so 0000-00-00 00:00:00 turns into -0001113TT0::0::00, which is an invalid ISO8601 date

Attachments (6)

patch-core-19733.diff (2.4 KB) - added by koke 18 months ago.
patch-core-19733-2.diff (11.8 KB) - added by markoheijnen 16 months ago.
patch-core-19733-3.diff (12.4 KB) - added by markoheijnen 15 months ago.
patch-core-19733-4.diff (12.8 KB) - added by markoheijnen 15 months ago.
patch-core-19733-4.2.diff (12.8 KB) - added by markoheijnen 15 months ago.
patch-core-19733-5.diff (12.3 KB) - added by markoheijnen 15 months ago.

Download all attachments as: .zip

Change History (20)

koke18 months ago

comment:1 koke18 months ago

  • Keywords has-patch mobile added

Added a patch which sets the post_date_gmt value to the converted post_date for pending and auto-draft posts.

comment:2 daniloercoli18 months ago

  • Cc ercoli@… added

comment:3 DrewAPicture18 months ago

Related #16985 #18998

Last edited 18 months ago by DrewAPicture (previous) (diff)

comment:4 nacin18 months ago

  • Milestone changed from Awaiting Review to 3.4

Looks good to me.

comment:5 koke18 months ago

Also, IXR_Date doesn't like "weird" dates.

  • mysql2date returns -00011130T00:00:00. It looks weird but it makes sense: 0000-00-00 -> -1-12-00 -> -1-11-30
  • IXR_Date works by taking substrings, and the leading '-' is what breaks everything.

Using a NULL for a 'zero' date might make sense, but I wonder how many things would break, probably including XML-RPC :(

comment:6 markoheijnen16 months ago

  • Cc marko@… added

Added a new patch at #18429 that also fixes this issue. Do need to test it tomorrow if it works as it should.

comment:7 westi16 months ago

In [20153]:

XMLRPC: Intoduce a date generation helper method to improve the dates returned over XMLRPC when we have a 0 date stored for drafts.

This improves the ability of clients to work with the new wp Post APIs. See #18429 and #19733 props maxcutler.

comment:8 markoheijnen16 months ago

Added a patch that applies the patch of maxcutler to all the methods. I didn't applied the code of the first patch of this ticket. Is that still needed?

comment:9 maxcutler16 months ago

  • Cc max@… added

comment:10 westi15 months ago

  • Keywords needs-unit-tests added

I would really like to have the last patch in 3.4 but I also really don't want to commit it without us adding test cases because I just found a bunch of bugs in the featured image stuff we applied everywhere by writing the basic test cases for mw_(new|edit)_Post.

If someone wants to write up some tests to cover the date stuff that would be really helpful.

comment:11 markoheijnen15 months ago

I applied the patch of koke in a way that it only applies for incorrect dates. No matter what the post status is.
I also applied it to all the new XML-RPC methods so everything has the same date handling.

A benefit for this patch is that _convert_date and _convert_date_gmt only return an IXR_Date.

comment:12 westi15 months ago

I took a look at the last patch and all looks good apart from:

  • _convert_mysql2date is a level of abstraction too far - lets just call mysql2date directly.
  • $this-> _convert_date( $date_gmt ); - space in this.

@markoheijnen could you give the patch a refresh to address these?

comment:13 markoheijnen15 months ago

Fixed that in patch-core-19733-5.diff

comment:14 westi15 months ago

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

In [20353]:

XMLRPC: Make sure that we always return valid dates when no date is currently set - for example if the post is pending. Fixes #19733 props markoheijnen and koke.

Note: See TracTickets for help on using tickets.