[wp-trac] [WordPress Trac] #11722: body_class() creates an invalid class when page template contains a . [full stop] (was: body_class() creates an invalid class when page template contains a . [dot])

WordPress Trac wp-trac at lists.automattic.com
Tue Jan 5 14:02:36 UTC 2010


#11722: body_class() creates an invalid class when page template contains a . [full
stop]
--------------------------+-------------------------------------------------
 Reporter:  willmot       |       Owner:            
     Type:  defect (bug)  |      Status:  new       
 Priority:  low           |   Milestone:  3.0       
Component:  Template      |     Version:  3.0       
 Severity:  minor         |    Keywords:  body_class
--------------------------+-------------------------------------------------

Comment(by willmot):

 The full stop in the file extension is properly escaped.

 This happens in line 440 of wp-includes/post-template.php

 {{{
 $classes[] = 'page-template-' . str_replace( '.php', '-php',
 get_post_meta( $pageID, '_wp_page_template', true ) );
 }}}

 Attached patch simple removes the str_replace and uses the
 sanitize_html_class function instead.

 There could be a somewhat minor backwards compat issue as
 sanitize_html_class simple removes invalid characters instead replacing
 them with a hyphen which means that the file extension is sanitized to
 "php" instead of "-php".

 Also I pass an empty fallback to sanitize_html_class, is there something
 better we could show in the unlikely event that someone has a filename
 that contains only invalid characters. Perhaps just the string "invalid-
 filename" or something.

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


More information about the wp-trac mailing list