Ticket #5599: 5599.2.diff

File 5599.2.diff, 2.3 KB (added by ryan, 4 years ago)
  • wp-includes/streams.php

     
    5858  function StringReader($str='') { 
    5959    $this->_str = $str; 
    6060    $this->_pos = 0; 
     61    // If string functions are overloaded, we need to use the mb versions 
     62    $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); 
    6163  } 
    6264 
    6365  function read($bytes) { 
     66    if ($this->is_overloaded) return $this->mb_read($bytes); 
    6467    $data = substr($this->_str, $this->_pos, $bytes); 
    6568    $this->_pos += $bytes; 
    6669    if (strlen($this->_str)<$this->_pos) 
     
    6871 
    6972    return $data; 
    7073  } 
     74   
     75  function mb_read($bytes) { 
     76    $data = mb_substr($this->_str, $this->_pos, $bytes, 'ascii'); 
     77    $this->_pos += $bytes; 
     78    if (mb_strlen($this->_str, 'ascii')<$this->_pos) 
     79      $this->_pos = mb_strlen($this->_str, 'ascii'); 
    7180 
     81    return $data; 
     82  } 
     83 
    7284  function seekto($pos) { 
     85    if ($this->is_overloaded) return $this->mb_seekto($pos); 
    7386    $this->_pos = $pos; 
    7487    if (strlen($this->_str)<$this->_pos) 
    7588      $this->_pos = strlen($this->_str); 
    7689    return $this->_pos; 
    7790  } 
     91   
     92  function mb_seekto($pos) { 
     93    $this->_pos = $pos; 
     94    if (mb_strlen($this->_str, 'ascii')<$this->_pos) 
     95      $this->_pos = mb_strlen($this->_str, 'ascii'); 
     96    return $this->_pos; 
     97  } 
    7898 
    7999  function currentpos() { 
    80100    return $this->_pos; 
    81101  } 
    82  
     102   
    83103  function length() { 
     104    if ($this->is_overloaded) return $this->mb_length(); 
    84105    return strlen($this->_str); 
    85106  } 
    86107 
     108  function mb_length() { 
     109    return mb_strlen($this->str, 'ascii'); 
     110  } 
     111   
    87112} 
    88113 
    89114 
     
    149174// over it (it assumes knowledge of StringReader internals) 
    150175class CachedFileReader extends StringReader { 
    151176  function CachedFileReader($filename) { 
     177    parent::StringReader(); 
     178 
    152179    if (file_exists($filename)) { 
    153180 
    154181      $length=filesize($filename); 
    155182      $fd = fopen($filename,'rb'); 
    156183 
    157184      if (!$fd) { 
    158         $this->error = 3; // Cannot read file, probably permissions 
    159         return false; 
     185        $this->error = 3; // Cannot read file, probably permissions 
     186        return false; 
    160187      } 
    161188      $this->_str = fread($fd, $length); 
    162           $this->_pos = 0; 
    163189          fclose($fd); 
    164190 
    165191    } else {