Opened 17 years ago
Closed 17 years ago
#4433 closed defect (bug) (fixed)
duplicate post_name is possible
Reported by: | 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.
Diff for wp-includes/post.php to fix bug