From 3d9f38f1e390f77b8b17059df378c976acaae4a4 Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 25 Jun 2018 00:46:07 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B1=B4=EA=B5=AD=20=EB=93=B1=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EC=9E=85=EB=A0=A5=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/c_double.php | 18 +++--------------- src/sammo/StringUtil.php | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 16 deletions(-) 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 '';