diff --git a/hwe/c_double.php b/hwe/c_double.php index dec5ac2f..a6e4c385 100644 --- a/hwe/c_double.php +++ b/hwe/c_double.php @@ -44,11 +44,7 @@ $comStr = EncodeCommand($fourth, $third, $double, $command); // 건국 if($command == 46) { - $name = htmlspecialchars($name); - $name = StringUtil::removeSpecialCharacter($name); - $name = StringUtil::subStringForWidth($name, 0, 18); - $name = WebUtil::htmlPurify($name); - $name = StringUtil::textStrip($name); + $name = StringUtil::neutralize($name); if($name == "") { $name = "무명"; } $db->update('general', [ @@ -72,11 +68,7 @@ if($command == 53) { $me = MYDB_fetch_array($result); if($me['level'] >= 5) { - $nationname = htmlspecialchars($nationname); - $nationname = StringUtil::removeSpecialCharacter($nationname); - $nationname = StringUtil::subStringForWidth($nationname, 0, 18); - $nationname = WebUtil::htmlPurify($nationname); - $nationname = StringUtil::textStrip($nationname); + $nationname = StringUtil::neutralize($nationname, 18); if($nationname == "") { $nationname = "무명"; } $db->update('general', [ @@ -102,11 +94,7 @@ if($command == 61) { $me = MYDB_fetch_array($result); if($me['level'] >= 5) { - $note = htmlspecialchars($note); - $note = StringUtil::removeSpecialCharacter($note); - $note = StringUtil::subStringForWidth($note, 0, 90); - $note = WebUtil::htmlPurify($note); - $note = StringUtil::textStrip($note); + $note = StringUtil::neutralize($note, 90); $query = "update diplomacy set reserved='{$note}' where me='{$me['nation']}' and you='$double'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); diff --git a/src/sammo/StringUtil.php b/src/sammo/StringUtil.php index 31f2f3a8..dfb6c363 100644 --- a/src/sammo/StringUtil.php +++ b/src/sammo/StringUtil.php @@ -143,13 +143,30 @@ class StringUtil return static::padString($str, $maxsize, $ch, 0); } - public static function escapeTag($str) + public static function escapeTag(?string $str):string { + if(!$str){ + return ''; + } $str = htmlspecialchars($str); $str = str_replace(["\r\n", "\r", "\n"], '
', $str); return $str; } + public static function neutralize(?string $str, ?int $maxLen = null){ + if(!$str){ + return ''; + } + if($maxLen && $maxLen > 0){ + $str = StringUtil::subStringForWidth($str, 0, $maxLen); + } + $str = htmlspecialchars($str); + $str = StringUtil::removeSpecialCharacter($str); + $str = WebUtil::htmlPurify($str); + $str = StringUtil::textStrip($str); + return $str; + } + public static function textStrip(?string $str):string{ if(!$str){ return '';