WordPress.org

Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#7230 closed defect (bug) (fixed)

The 0th of July

Reported by: tellyworth Owned by:
Milestone: 2.6 Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

It's possible to enter a post date with a zero on the write post page. WP doesn't validate the date, and unless MySQL is running in strict mode the invalid date will get stored in the post_date column.

Steps to reproduce:

  1. New Post
  1. Edit the timestamp
  1. Change the day field to "00"
  1. Publish
  1. Click the View Post link

Expected: WP should validate the date and change it to something that works.

Actual: the post is published but the permalink is 404 because of a quirk in the way get_permalink() handles the post_date field.

The steps to reproduce assume MySQL is not running in strict mode, I haven't tested that case. Reproduced in trunk, it probably affects all versions.

Attachments (2)

no_zero_dates.diff (550 bytes) - added by ryan 12 years ago.
date-validation-r8244.patch (770 bytes) - added by tellyworth 12 years ago.
checkdate() and time validation too

Download all attachments as: .zip

Change History (10)

#1 @tellyworth
12 years ago

Just to clarify, the post_date field actually stores '2008-07-00' if you do this. It's a MySQL feature, believe it or not.

@ryan
12 years ago

#2 @ryan
12 years ago

Quick fix. Year, month, or day <=0 are given the current year, month, or day instead.

@tellyworth
12 years ago

checkdate() and time validation too

#3 @tellyworth
12 years ago

My take is in the new patch. It uses checkdate() to cover other invalid dates, and also fixes a minor bug in the time validation (e.g. hours > 48 wasn't handled correctly).

#4 @ryan
12 years ago

If we use checkdate() we need to put it in a hook so that non-Gregorian calendars can be supported.

#5 @tellyworth
12 years ago

Ah fair enough, I didn't know we supported them. Take the simpler approach for now then.

#6 @ryan
12 years ago

Looks like I accidentally checked it in with [8248].

#7 @ryan
12 years ago

  • Milestone changed from 2.5.2 to 2.6

#8 @ryan
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.