From 13d354ba8c9520234de2e90cf41fa04f7f7fb837 Mon Sep 17 00:00:00 2001 From: liyuchun Date: Mon, 18 Apr 2022 11:35:36 +0800 Subject: [PATCH] * Fix bug #21518. --- lib/base/filter/filter.class.php | 19 +++++++++++++++++++ module/testcase/model.php | 12 ++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/base/filter/filter.class.php b/lib/base/filter/filter.class.php index 8db2523369..020f440076 100644 --- a/lib/base/filter/filter.class.php +++ b/lib/base/filter/filter.class.php @@ -1370,4 +1370,23 @@ class baseFixer foreach($fields as $key => $fieldName) if(!isset($this->data->$fieldName)) unset($fields[$key]); return $fields; } + + /** + * 过滤Emoji表情。 + * Filter Emoji. + * + * @param string $fieldName + * @access public + * @return object + */ + public function filterEmoji($fieldName){ + $fields = $this->processFields($fieldName); + foreach($fields as $fieldName) + { + $this->data->$fieldName = preg_replace_callback('/./u', function (array $match){ + return strlen($match[0]) >= 4 ? '' : $match[0]; + }, $this->data->$fieldName); + } + return $this; + } } diff --git a/module/testcase/model.php b/module/testcase/model.php index 1158b7b9b7..5a40c8347f 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -71,7 +71,9 @@ class testcaseModel extends model $this->loadModel('file')->saveUpload('testcase', $caseID); $parentStepID = 0; $this->loadModel('score')->create('testcase', 'create', $caseID); - foreach($this->post->steps as $stepID => $stepDesc) + + $data = fixer::input('post')->filterEmoji('steps,expects')->get(); + foreach($data->steps as $stepID => $stepDesc) { if(empty($stepDesc)) continue; $stepType = $this->post->stepType; @@ -81,7 +83,7 @@ class testcaseModel extends model $step->case = $caseID; $step->version = 1; $step->desc = htmlSpecialString($stepDesc); - $step->expect = $step->type == 'group' ? '' : htmlSpecialString($this->post->expects[$stepID]); + $step->expect = $step->type == 'group' ? '' : htmlSpecialString($data->expects[$stepID]); $this->dao->insert(TABLE_CASESTEP)->data($step)->autoCheck()->exec(); if($step->type == 'group') $parentStepID = $this->dao->lastInsertID(); if($step->type == 'step') $parentStepID = 0; @@ -741,7 +743,9 @@ class testcaseModel extends model /* Ignore steps when post has no steps. */ if($this->post->steps) { - foreach($this->post->steps as $stepID => $stepDesc) + $data = fixer::input('post')->filterEmoji('steps,expects')->get(); + + foreach($data->steps as $stepID => $stepDesc) { if(empty($stepDesc)) continue; $stepType = $this->post->stepType; @@ -751,7 +755,7 @@ class testcaseModel extends model $step->case = $caseID; $step->version = $version; $step->desc = htmlSpecialString($stepDesc); - $step->expect = $step->type == 'group' ? '' : htmlSpecialString($this->post->expects[$stepID]); + $step->expect = $step->type == 'group' ? '' : htmlSpecialString($data->expects[$stepID]); $this->dao->insert(TABLE_CASESTEP)->data($step)->autoCheck()->exec(); if($step->type == 'group') $parentStepID = $this->dao->lastInsertID(); if($step->type == 'step') $parentStepID = 0;