[Tickets #11930] Re: Horde_String::validUtf8 fails to validate valid UTF8

noreply at bugs.horde.org noreply at bugs.horde.org
Wed Jan 9 21:01:58 UTC 2013


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/11930
------------------------------------------------------------------------------
  Ticket             | 11930
  Updated By         | tassoskalyvas at gmail.com
  Summary            | Horde_String::validUtf8 fails to validate valid UTF8
  Queue              | Horde Framework Packages
  Version            | Git master
  Type               | Bug
  State              | Resolved
  Priority           | 1. Low
  Milestone          |
  Patch              |
  Owners             | Michael Slusarz
------------------------------------------------------------------------------


tassoskalyvas at gmail.com (2013-01-09 21:01) wrote:

a quick reference  i found without reading the whole paper is table 3.7 in
http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf
a implementation of the table i crafted is  bellow

   static public function validUtf8($text)
     {
     $text = strval($text);
	$len = strlen($text);
         for ($i = 0; $i < $len;  $i++) {
             $c = ord($text[$i]);
             if ($c >= 128) {
                 if ($c > 244) return false;
                 	elseif ($c > 239)  {$bytes = 4;
                 		if ($c = 240)  {$c1 = ord($text[$i+1]);
                 			if (($c1 < 144)) return false;}
                 		if ($c = 244)  {$c1 = ord($text[$i+1]);
                 			if (($c1 > 144)) return false;}}
                 	elseif ($c > 223)  {$bytes = 3;
						if ( $c = 237) {$c1 = ord($text[$i+1]);
							if (($c1 > 159)) return false;}
						if ( $c = 224) {$c1 = ord($text[$i+1]);
							if (($c1 < 160)) return false;}}
                 	elseif ($c > 193)  $bytes = 2;
				else  return false;
                 if (($i + $bytes) > $len)   return false;
                 while ($bytes >  1) {
		    		$i++;
                     $c = ord($text[$i]);
                     if (($c < 128) || ($c > 191))    return false;
					$bytes--;

                 }
             }
         }

         return true;
     }

Warning i am not a programmer





More information about the bugs mailing list