[wp-trac] [WordPress Trac] #4433: duplicate post_name is possible
WordPress Trac
wp-trac at lists.automattic.com
Tue Jun 12 14:42:58 GMT 2007
#4433: duplicate post_name is possible
----------------------------+-----------------------------------------------
Reporter: AaronCampbell | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone:
Component: Administration | Version: 2.2
Severity: normal | Keywords:
----------------------------+-----------------------------------------------
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.
--
Ticket URL: <http://trac.wordpress.org/ticket/4433>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list