Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4433 closed defect (bug) (fixed)

duplicate post_name is possible

Reported by: aaroncampbell's profile AaronCampbell Owned by:
Milestone: 2.3 Priority: normal
Severity: normal Version: 2.2
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

Since post_name (slug) is based on post_title, and both fields are the same length, you can end up with duplicate post_name entries. To duplicate the bug, come up with a 200+ char string. I used:
this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test zzzzzz

Put that as the title, and add the post. Then do it again with the same title.

What's happening:
You have "200charstring" in the db, and attempt to submit it again. "200charstring" exists, so it tries "200charstring-2" which does not exist, so it puts that in there, but since it's a 200 char limit, it gets cut down to "200charstring" and you get a duplicate

Possible fixes:
The best solution (in my opinion) would be to replace line 603 of post.php:
$alt_post_name = $post_name . "-$suffix";
with this:
$alt_post_name = substr($post_name, 0, 200-(strlen($suffix)+1)). "-$suffix";

Alternatively, a quick and dirty fix would be to make the post_name field a few characters longer than the post_title field. Still there would be limits, but if you make it 5 characters longer, you could have 9,999 duplicate names over 200 characters with no problems.

I'm attaching a .diff for the first fix.

Attachments (1)

post.diff (628 bytes) - added by AaronCampbell 17 years ago.
Diff for wp-includes/post.php to fix bug

Download all attachments as: .zip

Change History (4)

@AaronCampbell
17 years ago

Diff for wp-includes/post.php to fix bug

#1 @rob1n
17 years ago

  • Milestone set to 2.3 (trunk)

#2 @Nazgul
17 years ago

  • Keywords has-patch added

#3 @markjaquith
17 years ago

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

(In [5685]) Make sure post titles longer than 200 chars get unique slugs. fixes #4433. props AaronCampbell.

Note: See TracTickets for help on using tickets.