[wp-trac] [WordPress Trac] #21841: redirect_canonical produces invalid redirects when post ID is specified

WordPress Trac wp-trac at lists.automattic.com
Sun Sep 9 23:44:10 UTC 2012


#21841: redirect_canonical produces invalid redirects when post ID is specified
--------------------------+------------------
 Reporter:  solarissmoke  |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  3.5
Component:  Canonical     |     Version:  3.4
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------
Changes (by SergeyBiryukov):

 * keywords:   => has-patch
 * milestone:  Awaiting Review => 3.5


Comment:

 Introduced in [20396], so it's indeed a regression in 3.4.

 > `http://example.com/?p=1&feed=rss2`
 > Assuming a post with that ID exists, this is valid and shouldn't be
 redirected anywhere.

 Actually, the canonical URL for post comments feed without pretty
 permalinks would be `http://example.com/?feed=rss2&p=1` (also broken in
 3.4). The bug is the encoded ampersand.

 1. `get_post_comments_feed_link()` returns `&` as an entity: [[BR]]
  http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/link-
 template.php#L489 [[BR]]
  (`get_edit_post_link()` has a context parameter for that, but other
 functions don't.) [[BR]]
  http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/link-
 template.php#L895 [[BR]]

 2. Because of that, `$redirect_url` and `$requested_url` do not match:
 {{{
 $redirect_url: http://trunk.wordpress/?feed=rss2&p=1
 $requested_url: http://trunk.wordpress/?feed=rss2&p=1
 }}}
  And a pointless redirect is performed.

 Not sure what's the best way to fix this, but [attachment:21841.patch]:
 1. Doesn't break the canonical URL
 (`http://trunk.wordpress/?feed=rss2&p=1`).
 2. Properly redirects `http://example.com/?p=1&feed=rss2` to the canonical
 URL.
 3. Passes our current unit tests (might need new).

 There's a similar replacement in `wp_nonce_url()`: [[BR]]
 http://core.trac.wordpress.org/browser/tags/3.4.2/wp-
 includes/functions.php#L1154

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21841#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list