[wp-trac] [WordPress Trac] #12251: mb_substr() works strangely in some environment.

WordPress Trac wp-trac at lists.automattic.com
Tue Feb 16 15:13:56 UTC 2010


#12251: mb_substr() works strangely in some environment.
--------------------------+-------------------------------------------------
 Reporter:  Cyrus H.      |       Owner:  nbachiyski
     Type:  defect (bug)  |      Status:  new       
 Priority:  high          |   Milestone:  2.9.3     
Component:  i18n          |     Version:  2.9.2     
 Severity:  normal        |    Keywords:            
--------------------------+-------------------------------------------------
 http://wordpress.org/support/topic/357562

 First of all, this is not a P2 theme bug; this is WP core bug.
 I use English WordPress, but I post a post in Korean.

 Summarizing above link: mb_substr() and mb_strlen() shows malfunction when
 dealing with non-English characters, because '''encoding parameter is not
 specified'''. This happens when PHP MB extension is enabled, because
 backward-compatibility function _mb_substr() automatically assumes the
 encoding as UTF-8 but the extension does not.

 Following '''should be''' adopted to 2.9.3:


 FILE: /wp-admin/includes/plugin-install.php, line 332[[BR]]
 FROM:[[BR]]
 $description = mb_substr($description, 0, 400) . '…';[[BR]]
 TO:[[BR]]
 $description = mb_substr($description, 0, 400, 'UTF-8') . '…';[[BR]]


 FILE: /wp-admin/includes/post.php, line 1037[[BR]]
 FROM:[[BR]]
 if ( mb_strlen($post_name) > 30 ) {[[BR]]
 TO:[[BR]]
 if ( mb_strlen($post_name, 'UTF-8') > 30 ) {[[BR]]


 FILE: /wp-admin/includes/post.php, line 1038[[BR]]
 FROM:[[BR]]
 $post_name_abridged = mb_substr($post_name, 0, 14). '…' .
 mb_substr($post_name, -14);[[BR]]
 TO:[[BR]]
 $post_name_abridged = mb_substr($post_name, 0, 14, 'UTF-8'). '…' .
 mb_substr($post_name, -14, 14, 'UTF-8');[[BR]]


 FILE: /wp-includes/formatting.php, line 2708[[BR]]
 FROM:[[BR]]
 $str = mb_substr( $str, 0, $count );[[BR]]
 TO:[[BR]]
 $str = mb_substr( $str, 0, $count, 'UTF-8' );[[BR]]


 Personally, this is very inconvenient: it gives me stress of seeing
 Unicode Replacement Character.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12251>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list