[wp-trac] Re: [WordPress Trac] #8446: post_class() outputs invalid css class

WordPress Trac wp-trac at lists.automattic.com
Wed Apr 29 12:41:07 GMT 2009


#8446: post_class() outputs invalid css class
--------------------------+-------------------------------------------------
 Reporter:  lilyfan       |       Owner:  nbachiyski           
     Type:  defect (bug)  |      Status:  new                  
 Priority:  high          |   Milestone:  2.8                  
Component:  i18n          |     Version:  2.7                  
 Severity:  major         |    Keywords:  has-patch 2nd-opinion
--------------------------+-------------------------------------------------

Comment(by hakre):

 thanks for taking the time to take a look into it.

 yes we need split_utf8(), it is not only used in seems_utf8():
 {{{
 $partsUtf8      = split_utf8($class);
 }}}
 it is used in seems_utf8() to not have code-duplication. you can see that
 a lot of the code from both functions is the same (well seems_utf8() is
 not that improved as split_utf8() but both have the same logic).

 split_utf8() is used to validate single byte chars to macht the CSS
 definition since multi byte utf8 sequnces are per-se valid for the css
 classname. The following fragement shows that:

 {{{
         104             $partsUtf8      = split_utf8($class);
         105             $count                  = count($partsUtf8);
         106             if (is_array($partsUtf8) && $count !=
 strlen($class)) { // has multi byte chars
         107
         108                     // filter invalid chars per entity, only
 single chars need to me checked
         109                     for ($i=0; $i < $count; $i++) {
         110                             if (strlen($partsUtf8[$i]) == 1) {
         111                                     $partsUtf8[$i] =
 preg_replace('|[^_a-zA-Z0-9\0-\177-]|', '_', $partsUtf8[$i]);
         112                             }
         113                     }
         114                     $class = implode($partsUtf8); // rebuild
 class string
         115             }
 }}}

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


More information about the wp-trac mailing list