1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-27 17:00:52 +01:00

Merge pull request #550 from f89s/master

Fix combining character set, allow limit for combining characters
This commit is contained in:
RealAngeleno 2023-04-22 09:31:06 -07:00 committed by GitHub
commit f8c8d57d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 13 deletions

View File

@ -485,8 +485,11 @@
// Strip superfluous new lines at the end of a post. // Strip superfluous new lines at the end of a post.
$config['strip_superfluous_returns'] = true; $config['strip_superfluous_returns'] = true;
// Strip combining characters from Unicode strings (eg. "Zalgo"). /// Strip combining characters from Unicode strings (eg. "Zalgo"). This will impact some non-English languages.
$config['strip_combining_chars'] = true; $config['strip_combining_chars'] = true;
// Maximum number of combining characters in a row allowed in Unicode strings so that they can still be used in moderation.
// Requires $config['strip_combining_chars'] = true;
$config['max_combining_chars'] = 3;
// Maximum post body length. // Maximum post body length.
$config['max_body'] = 1800; $config['max_body'] = 1800;

View File

@ -2330,19 +2330,11 @@ function ordutf8($string, &$offset) {
return $code; return $code;
} }
// Limit Non_Spacing_Mark and Enclosing_Mark characters
function strip_combining_chars($str) { function strip_combining_chars($str) {
$chars = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY); global $config;
$str = ''; $limit = strval($config['max_combining_chars']+1);
foreach ($chars as $char) { return preg_replace('/(\p{Me}|\p{Mn}){'.$limit.',}/u','', $str);
$o = 0;
$ord = ordutf8($char, $o);
if ( ($ord >= 768 && $ord <= 879) || ($ord >= 1536 && $ord <= 1791) || ($ord >= 3655 && $ord <= 3659) || ($ord >= 7616 && $ord <= 7679) || ($ord >= 8400 && $ord <= 8447) || ($ord >= 65056 && $ord <= 65071))
continue;
$str .= $char;
}
return $str;
} }
function buildThread($id, $return = false, $mod = false) { function buildThread($id, $return = false, $mod = false) {