Rename new function to sanitize_html_class() to hilight exactly what it is for, Fixes #8446.

git-svn-id: http://svn.automattic.com/wordpress/trunk@11435 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-05-22 21:31:42 +00:00
parent acfc3cdf1a
commit fc3b5ba6da
3 changed files with 21 additions and 17 deletions

View File

@ -294,7 +294,7 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
// For all registered users, 'byuser'
$classes[] = 'byuser';
$classes[] = 'comment-author-' . sanitise_css_classname($user->user_nicename, $comment->user_id);
$classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
// For comment authors who are the author of the post
if ( $post = get_post($post_id) ) {
if ( $comment->user_id === $post->post_author )

View File

@ -719,26 +719,30 @@ function sanitize_sql_orderby( $orderby ){
}
/**
* Santises a css classname to ensure it only contains valid characters
* Santizes a html classname to ensure it only contains valid characters
*
* Strips the classname down to A-Z,a-z,0-9,'-' if this results in an empty
* Strips the string down to A-Z,a-z,0-9,'-' if this results in an empty
* string then it will return the alternative value supplied.
*
* @todo Expand to support the full range of CDATA that a class attribute can contain.
*
* @param string $classname The classname to be sanitised
* @param string $alternative The value to return if the sanitisation end's up as an empty string.
* @return string The sanitised value
* @since 2.8.0
*
* @param string $class The classname to be sanitized
* @param string $fallback The value to return if the sanitization end's up as an empty string.
* @return string The sanitized value
*/
function sanitise_css_classname($classname, $alternative){
function sanitize_html_class($class, $fallback){
//Strip out any % encoded octets
$sanitised = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname);
$sanitized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $class);
//Limit to A-Z,a-z,0-9,'-'
$sanitised = preg_replace('/[^A-Za-z0-9-]/', '', $sanitised);
$sanitized = preg_replace('/[^A-Za-z0-9-]/', '', $sanitized);
if ('' == $sanitised)
$sanitised = $alternative;
if ('' == $sanitized)
$sanitized = $fallback;
return apply_filters('sanitise_css_classname',$sanitised, $classname, $alternative);
return apply_filters('sanitize_html_class',$sanitized, $class, $fallback);
}
/**

View File

@ -326,14 +326,14 @@ function get_post_class( $class = '', $post_id = null ) {
foreach ( (array) get_the_category($post->ID) as $cat ) {
if ( empty($cat->slug ) )
continue;
$classes[] = 'category-' . sanitise_css_classname($cat->slug, $cat->cat_ID);
$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
}
// Tags
foreach ( (array) get_the_tags($post->ID) as $tag ) {
if ( empty($tag->slug ) )
continue;
$classes[] = 'tag-' . sanitise_css_classname($tag->slug, $tag->term_id);
$classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
}
if ( !empty($class) ) {
@ -407,15 +407,15 @@ function get_body_class( $class = '' ) {
if ( is_author() ) {
$author = $wp_query->get_queried_object();
$classes[] = 'author';
$classes[] = 'author-' . sanitise_css_classname($author->user_nicename , $author->user_id);
$classes[] = 'author-' . sanitize_html_class($author->user_nicename , $author->user_id);
} elseif ( is_category() ) {
$cat = $wp_query->get_queried_object();
$classes[] = 'category';
$classes[] = 'category-' . sanitise_css_classname($cat->slug, $cat->cat_ID);
$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
} elseif ( is_tag() ) {
$tags = $wp_query->get_queried_object();
$classes[] = 'tag';
$classes[] = 'tag-' . sanitise_css_classname($tags->slug, $tags->term_id);
$classes[] = 'tag-' . sanitize_html_class($tags->slug, $tags->term_id);
}
} elseif ( is_page() ) {
$classes[] = 'page';