From e0f06bd939b9143cd35e47c042c9947435723d96 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Wed, 23 Dec 2009 09:52:48 +0000 Subject: [PATCH] Improve sanitize_text_field() some more so that we don't leave extra whitespace after stripping octets. Fixes #11573. git-svn-id: https://develop.svn.wordpress.org/trunk@12503 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/formatting.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 810381605d..8b2d999dc2 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -2834,14 +2834,18 @@ function sanitize_text_field($str) { if ( strpos($filtered, '<') !== false ) { $filtered = wp_pre_kses_less_than( $filtered ); + // This will strip extra whitespace for us. $filtered = wp_strip_all_tags( $filtered, true ); } else { - $filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) ); + $filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) ); } $match = array(); - while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) + while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) { $filtered = str_replace($match[0], '', $filtered); + } + // Strip out the whitespace that may now exist after removing the octets. + $filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) ); return apply_filters('sanitize_text_field', $filtered, $str); }