Make WordPress Core

Opened 14 years ago

Closed 11 years ago

#21167 closed enhancement (wontfix)

Problem with custom permalinks

Reported by: kaffeeringe Owned by:
Priority: normal Milestone:
Component: Permalinks Version: 3.4
Severity: normal Keywords: needs-patch dev-feedback
Cc: Focuses:

Description

I am currently moving my blog (​http://kaffeeringe.de/) to Wordpress and I don't want to break my old URLs (Cool URLs don't change). The problem is, that these custom URLs don't work in Wordpress 3.4.1:

/blog/%postname%/%post_id%.html works
/blog/%postname%.%post_id%.html (which I need) doesn't work.

It doesn't work with the . in between these parameters…

I hope somebody is able to help me.

Attachments (4)

21167.patch​ (667 bytes ) - added by SergeyBiryukov 14 years ago.
21167.2.patch​ (502 bytes ) - added by SergeyBiryukov 14 years ago.
21167-unit-test.patch​ (3.1 KB ) - added by kurtpayne 14 years ago.
Unit test
21167-tests.patch​ (3.1 KB ) - added by boonebgorges 12 years ago.
Removing from trunk as per #30284

Download all attachments as: .zip

Change History (31)

#1 @Ipstenu
14 years ago

  • Keywords close added
  • Resolution → invalid
  • Status new → closed

This isn't a bug - Trac is for submitted bugs in WordPress :)

You should post in the WordPress forums instead (and I would in this case use a .htaccess to parse /blog/%postname%.%post_id%.html into /blog/%postname%/%post_id%/ (or anything else you wanted)

​http://wordpress.org/support if you need more help.

#2 @helenyhou
14 years ago

  • Milestone Awaiting Review

#3 @nacin
14 years ago

  • Resolution invalid
  • Status closed → reopened

Sounds like a bug to me. We allow random characters in a URL permalink structure, like ".html". Would be interesting to see where and why this fails.

#4 @helenyhou
14 years ago

  • Keywords close removed
  • Milestone → Awaiting Review

#5 @nacin
14 years ago

  • Type defect (bug) → enhancement

Looks like our support for this is quite tenuous. Many combinations work, but mostly by happenstance.

#6 @Ipstenu
14 years ago

/%postname%.%post_id%/ fails

/%year%.%monthnum%.%postname%/ works

/%post_id%.%postname%/ works

/%postname%.%year%/ works

Well now that's just odd...

Last edited 14 years ago by Ipstenu (previous) (diff)

#7 @sirzooro
14 years ago

  • Cc sirzooro added

I checked this and found that dot is not escaped when generating rules, e.g.:

  '([^/]+).([0-9]+)(/[0-9]+)?/?$' => 'index.php?name=$1&p=$2&page=$3'

Other special RX chars may also cause problems here - need to check if patch will work with them too.

#8 @SergeyBiryukov
14 years ago

  • Keywords has-patch added

21167.patch​ is an attempt to escape the special characters which are currently allowed in permalink structure and are acceptable in terms of valid URLs.

Seems to work in the following cases:

/%postname%.%post_id%/
/%postname%+%post_id%/
/%postname%$%post_id%/
/%postname%(%post_id%)/

#9 follow-up: @dd32
14 years ago

Is there any reason why we can't just run the permastructure through preg_quote()?

> preg_quote( '.+/()$[]%' );
\.\+/\(\)\$\[\]%

#10 in reply to: ↑ 9 @SergeyBiryukov
14 years ago

Replying to dd32:

Is there any reason why we can't just run the permastructure through preg_quote()?

Thanks, that indeed makes more sense.

#11 @SergeyBiryukov
14 years ago

  • Keywords needs-unit-tests added
  • Milestone Awaiting Review → 3.5

#12 @kurtpayne
14 years ago

  • Cc kpayne@… added

Unit test added, 21167.2.patch​ looks good. Let me know if there are any test cases missing.

#13 @tlovett1
14 years ago

  • Owner set to tlovett1
  • Status reopened → accepted

#14 @tlovett1
14 years ago

  • Owner tlovett1 removed
  • Status accepted → assigned

#15 @nacin
14 years ago

  • Keywords commit added

#16 @wonderboymusic
14 years ago

@kurtpayne - was that unit test patch committed?

#17 @SergeyBiryukov
14 years ago

  • Keywords needs-unit-tests removed

#19 @ryan
14 years ago

  • Resolution → fixed
  • Status assigned → closed

#20 @xknown
14 years ago

  • Resolution fixed
  • Status closed → reopened

The fix is probably incomplete. We should be passing the second argument on preg_quote and use the same delimiter where rewrite rules are being used.

For example, having the following permalink structure "/%post_id%#foo" (yes, probably unrealistic) would produce an invalid regular expression in wp-includes/class-wp.php, where # is used as a delimiter.
​http://core.trac.wordpress.org/browser/trunk/wp-includes/rewrite.php#L344
​http://core.trac.wordpress.org/browser/trunk/wp-includes/class-wp.php#L204

#21 @ryan
14 years ago

  • Keywords has-patch commit removed

#22 @nacin
14 years ago

Seems to me like this should be preg_quote()'d before getting used in a regexp, rather than on save.

#23 @jeremyfelt
14 years ago

Using preg_quote() breaks rewrites for post types with hyphens. I'm not entirely sure how supported that is to begin with, but I know I need to convert a few now. :)

#24 @ryan
14 years ago

In 22403:

Revert [22365]. see #21167

#25 @ryan
14 years ago

  • Milestone 3.5 → Future Release

@boonebgorges
12 years ago

Removing from trunk as per #30284

#26 @chriscct7
11 years ago

  • Keywords needs-patch dev-feedback added

#27 @johnbillion
11 years ago

  • Milestone Future Release
  • Resolution → wontfix
  • Status reopened → closed

No interest in three years. Feel free to re-open with a patch/tests.

Note: See TracTickets for help on using tickets.