[wp-trac] [WordPress Trac] #52131: wp_check_invalid_utf8() - PHP Notice: iconv()

WordPress Trac noreply at wordpress.org
Sun Dec 20 12:45:22 UTC 2020


#52131: wp_check_invalid_utf8() - PHP Notice:  iconv()
---------------------------+-----------------------------
 Reporter:  campusboy1987  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Formatting     |    Version:  5.6
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Hello. I test the function and php issues warnings.

 13 examples:
 {{{
 $examples = [
         'Valid ASCII'                               => "a",
         'Valid 2 Octet Sequence'                    => "\xc3\xb1",
         'Invalid 2 Octet Sequence'                  => "\xc3\x28",
         'Invalid Sequence Identifier'               => "\xa0\xa1",
         'Valid 3 Octet Sequence'                    => "\xe2\x82\xa1",
         'Invalid 3 Octet Sequence (in 2nd Octet)'   => "\xe2\x28\xa1",
         'Invalid 3 Octet Sequence (in 3rd Octet)'   => "\xe2\x82\x28",
         'Valid 4 Octet Sequence'                    => "\xf0\x90\x8c\xbc",
         'Invalid 4 Octet Sequence (in 2nd Octet)'   => "\xf0\x28\x8c\xbc",
         'Invalid 4 Octet Sequence (in 3rd Octet)'   => "\xf0\x90\x28\xbc",
         'Invalid 4 Octet Sequence (in 4th Octet)'   => "\xf0\x28\x8c\x28",
         'Valid 5 Octet Sequence (but not Unicode!)' =>
 "\xf8\xa1\xa1\xa1\xa1",
         'Valid 6 Octet Sequence (but not Unicode!)' =>
 "\xfc\xa1\xa1\xa1\xa1\xa1",
 ];

 $result = [];

 foreach ( $examples as $key => $value ) {
         $result[ $key ] = wp_check_invalid_utf8( $value, true );
 }
 }}}

 Result (4 not empty lines):
 {{{
 Array (
         [Valid ASCII]                               => a
         [Valid 2 Octet Sequence]                    => ñ
         [Invalid 2 Octet Sequence]                  =>
         [Invalid Sequence Identifier]               =>
         [Valid 3 Octet Sequence]                    => ₡
         [Invalid 3 Octet Sequence (in 2nd Octet)]   =>
         [Invalid 3 Octet Sequence (in 3rd Octet)]   =>
         [Valid 4 Octet Sequence]                    => 𐌼
         [Invalid 4 Octet Sequence (in 2nd Octet)]   =>
         [Invalid 4 Octet Sequence (in 3rd Octet)]   =>
         [Invalid 4 Octet Sequence (in 4th Octet)]   =>
         [Valid 5 Octet Sequence (but not Unicode!)] =>
         [Valid 6 Octet Sequence (but not Unicode!)] =>
 )
 }}}

 The following errors are displayed in the logs (9):

 {{{
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 Notice: iconv(): Detected an illegal character in input string in ...\wp-
 includes\formatting.php on line 1131
 }}}

 If you do not use the second argument of the function, then everything is
 fine.

 The warning generates the following code section:
 {{{
 // Attempt to strip the bad chars if requested (not recommended).
 if ( $strip && function_exists( 'iconv' ) ) {
     return iconv( 'utf-8', 'utf-8', $string );
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52131>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list