diff --git a/htdocs/application/models/pastes.php b/htdocs/application/models/pastes.php index 434e91a..9f8bdd3 100644 --- a/htdocs/application/models/pastes.php +++ b/htdocs/application/models/pastes.php @@ -19,6 +19,7 @@ * - delete_paste() * - random_paste() * - _format_diff() + * - _strip_bad_multibyte_chars() * Classes list: * - Pastes extends CI_Model */ @@ -55,7 +56,7 @@ class Pastes extends CI_Model $data['created'] = time(); //this is SO evil… saving the «raw» data with htmlspecialchars :-( (but I have to leave this, because of backwards-compatibility) - $data['raw'] = htmlspecialchars($this->input->post('code')); + $data['raw'] = htmlspecialchars($this->_strip_bad_multibyte_chars($this->input->post('code'))); $data['lang'] = htmlspecialchars($this->input->post('lang')); $data['replyto'] = $this->input->post('reply'); @@ -637,4 +638,27 @@ class Pastes extends CI_Model $text = '
' . $text . '
'; return $text; } + private + function _strip_bad_multibyte_chars($str) + { + $result = ''; + $length = strlen($str); + for ($i = 0;$i < $length;$i++) + { + + // Replace four-byte characters (11110www 10zzzzzz 10yyyyyy 10xxxxxx) + $ord = ord($str[$i]); + + if ($ord >= 240 && $ord <= 244) + { + $result.= '?'; + $i+= 3; + } + else + { + $result.= $str[$i]; + } + } + return $result; + } }