Make WordPress Core

Opened 17 years ago

Closed 16 years ago

#4273 closed defect (bug) (worksforme)

Posting comments to pages with øæå redirects to a 404 page

Reported by: orvar's profile orvar Owned by: westi's profile westi
Milestone: Priority: high
Severity: normal Version: 2.2
Component: Permalinks Keywords:
Focuses: Cc:

Description

[This is a repost of a ticket from the WPMU trac: http://trac.mu.wordpress.org/ticket/305]

How to reproduce

  • Create a page with a name that contains non-ascii characters (eg. øæå) that are not replaced with ascii characters in the slug.
  • Post a comment on that page.

The comment is saved but the user is not returned to the page. Instead he gets a 404 page not found error. After the comment has been saved to the db the user is redirected to a url where the specific non-asci characters are simply missing.

How to fix

This happens because get_permalink for a page returns a page name that has been urldecoded. Which is fine for links (old browsers?) but does not work in a Location: header.

Change get_page_uri in wp-includes/post.php to:

function get_page_uri($page_id, $decode = true) {
	$page = get_page($page_id);
	$uri = ( $decode ) ? urldecode($page->post_name) : $page->post_name;

	// A page cannot be it's own parent.
	if ( $page->post_parent == $page->ID )
		return $uri;

	while ($page->post_parent != 0) {
		$page = get_page($page->post_parent);
		$uri = ( $decode ) ? urldecode($page->post_name) . "/" . $uri : $page->post_name . "/" . $uri;
	}

	return $uri;
}

Change the call to get_page_uri in the function _get_page_link in wp-includes/link-template.php to:

		$link = get_page_uri($id, false);

I will try to post a diff for 2.2 later if nobody beats me to it.

Attachments (2)

4273-patch.txt (1.3 KB) - added by orvar 17 years ago.
4273.diff (618 bytes) - added by westi 17 years ago.
A simpler fix

Download all attachments as: .zip

Change History (12)

#1 @rob1n
17 years ago

  • Milestone changed from 2.2.1 to 2.3

@orvar
17 years ago

#2 @orvar
17 years ago

  • Version changed from 2.1.3 to 2.2

#3 @orvar
17 years ago

  • Keywords has-patch added

#4 @Kirin_Lin
17 years ago

  • Keywords needs-testing added; has-patch removed

Hi,
I'm Kirin. When i try to fix the problem, 'see comment:ticket:3727:27 ', I found we don't need to urldecode the post_name. But it needs more testing.

#5 @westi
17 years ago

  • Keywords has-patch added; needs-testing removed

I can reproduce this.

I am not convinced by the fix. urldecoding in get_page_uri ensures that the:

a-test-page-%c3%b8%c3%a6a is converted to a-test-page-\xc3\xb8\xc3\xa6a

This means we get the UTF8 chars in the browser source.

wp_redirect needs a url encoded sanitised link though and strips these chars out.

I will attach what I think is a better fix.

Testing done with PHP 5.2.4_pre200708051230-pl2-gentoo with Suhosin-Patch 0.9.6.2

@westi
17 years ago

A simpler fix

#6 @westi
17 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

#7 @westi
17 years ago

  • Keywords 2nd-opinion added

My patch above fixed the issue for me.

But I'm not entirely convinced this is the right place.

I support the question is - should get_permlink return urlencoded urls or not?

#8 @darkdragon
17 years ago

  • Component changed from General to i18n

#9 @lloydbudd
17 years ago

  • Milestone changed from 2.5 to 2.6

#10 @janbrasna
16 years ago

  • Cc janbrasna added
  • Component changed from i18n to Permalinks
  • Keywords has-patch 2nd-opinion removed
  • Milestone 2.9 deleted
  • Resolution set to worksforme
  • Status changed from assigned to closed

Seems fixed as of 2.7–RC2, the header sent (for page named "Testing broken øæå redirs") after posting a comment is:

Location: http://example.com/testing-broken-%c3%b8%c3%a6a-redirs/comment-page-1/#comment-6

which behaves correctly (Safari 3, Firefox 3).

Note: See TracTickets for help on using tickets.