Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#6934 closed defect (bug) (duplicate)

wp_insert_post and % in name

Reported by: libc's profile libc Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5.1
Component: General Keywords: wp_insert_post
Focuses: Cc:

Description

I'm writing import plugin.

post_title is “ViewSonic® Redefines Visual Technology Leadership with Introduction of Supe
rPDA and Tablet PC Products” (UTF-8)
wp_insert_post assigns post_name “viewsonic%c2%ae-redefines-visual-technology-leadership-with-introduction-of-superpda-and-tablet-pc-products”.

and (here)

	if ( 'draft' != $post_status ) {
		$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $post_name, $post_type, $post_ID, $post_parent));

		if ($post_name_check || in_array($post_name, $wp_rewrite->feeds) ) {
			$suffix = 2;
			do {
				$alt_post_name = substr($post_name, 0, 200-(strlen($suffix)+1)). "-$suffix";
				// expected_slashed ($alt_post_name, $post_name, $post_type)
				$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_type = '$post_type' AND ID != %d AND post_parent = %d LIMIT 1", $post_ID, $post_parent));
				$suffix++;
			} while ($post_name_check);
			$post_name = $alt_post_name;
		}
	}

when it calls $wpdb->prepare, it pass arguments to vsprintf, and it wanted more arguments, than I provide (becase of %c).
and $wpdb->prepare returns false. so this loop became infinite…

My temporary solution is

$alt_post_name = str_replace('%', '%%', substr($post_name, 0, 200-(strlen($suffix)+1)). "-$suffix");

but it's not adequate, because original $post_name_check fails, but should not. (good solution IMHO should be proper sanitize_title)
I tested it in 2.5 and 2.5.1.

Attachments (1)

6934.diff (1.8 KB) - added by xknown 17 years ago.

Download all attachments as: .zip

Change History (3)

@xknown
17 years ago

#1 follow-up: @ryan
17 years ago

Looks the same as #6894.

#2 in reply to: ↑ 1 @westi
17 years ago

  • Milestone 2.7 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Replying to ryan:

Looks the same as #6894.

Agreed. Closing as a duplicate of #6894 which is fixed for trunk and branches/2.5

Note: See TracTickets for help on using tickets.