Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#20399 closed defect (bug) (invalid)

WordPress removing multiple dashes/hyphens breaks my permalinks

Reported by: colinwiseman's profile colinwiseman Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: General Keywords:
Focuses: Cc:

Description (last modified by johnbillion)

Recently been trying to upgrade to WordPress 3.3.1 but a lot of our writers use characters like ~ and " in their titles, which am fine with as WordPress has always changed these to dashes. So our URLs have multiple dashes/hyphens.

I have tracked this down to line 892 of /wp-includes/formatting.php which is:

$title = preg_replace('|-+|', '-', $title);

and so it replaces more than 1 consecutive occurance of - with a single -. And this is as the point the code checks the database. Thus a URL e.g. "colin---wiseman---2012" gets changed to "colin-wiseman-2012" which is not a name of a post in the database.

We cannot go back and change all our URLs as there are 1000s of pages and linked to from all around the internet.

The only solution I have found is to comment out this line, but I'd rather there be an option in WordPress that I can flag in the wp-config e.g. define("SANATIZE_DASHES", false); so that the next time I upgrade wordpress there isn't this issue.

I feel that until then, this is a serious bug that could be affecting more blogs than just mine.

Change History (7)

#1 @johnbillion
13 years ago

  • Description modified (diff)

#2 in reply to: ↑ description @SergeyBiryukov
13 years ago

Replying to colinwiseman:

So our URLs have multiple dashes/hyphens.

This sounds strange.

That line was added in [774] and exists there since WordPress 1.0.1 "Miles", so under normal circumstances URLs should not contain multiple hyphens.

#3 @colinwiseman
13 years ago

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

It appears the version of WordPress I am working with was modified over 2 years ago (maybe by me, but there has been a couple of developers and no code respository). This has caused our issues, but am confused as we have upgraded a couple of times!

Please ignore this now while I go try and fix this! 2272 posts have multiple dashes in them :S

#4 @helenyhou
13 years ago

  • Milestone Awaiting Review deleted

#5 @nacin
13 years ago

Note that WordPress stores old post slugs in postmeta and then automatically does a 301 redirect from an old slug to a new slug.

So it should be relatively easy to handle.

#6 @colinwiseman
13 years ago

How would I have it set up to do this? Just resave the post?

#7 @colinwiseman
13 years ago

Ah yes. With 2272 posts I will need to write a script to do this :D Oh well the fun times of a programmer! But amazing that WordPress does that 301 automatically.

Thanks for all your time.

Colin

Note: See TracTickets for help on using tickets.