From dbc3f1e0d160500ebb7ca18350e165a2b4161ae7 Mon Sep 17 00:00:00 2001 From: sakaguchi Date: Fri, 22 May 2026 13:31:59 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20#4338=20=E3=80=90=E3=83=A1=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=80=91=E7=A2=BA=E8=AA=8D=E7=94=BB=E9=9D=A2=E3=81=A7?= =?UTF-8?q?=E9=80=81=E4=BF=A1=E6=99=82=E3=81=AB=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E3=81=A8=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=AB=E3=81=AA=E3=82=8B=E4=BB=B6=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-mail/src/Controller/MailController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/MailController.php b/plugins/bc-mail/src/Controller/MailController.php index 1efcc57fbe..06860febc7 100755 --- a/plugins/bc-mail/src/Controller/MailController.php +++ b/plugins/bc-mail/src/Controller/MailController.php @@ -281,7 +281,7 @@ public function submit( $entity = $mailMessagesService->create($mailContent, $this->getRequest()->getData()); } catch (PersistenceFailedException $e) { $entity = $e->getEntity(); - $mailMessage->auth_captcha = ''; + $entity->auth_captcha = ''; $this->BcMessage->setError(__d('baser_core', '入力内容を確認し、再度送信してください。')); $this->set($service->getViewVarsForConfirm($mailContent, $entity)); return $this->render($service->getConfirmTemplate($mailContent)); From 67feec3a4b0aa0089c835e0aa2926e2ec3ca560e Mon Sep 17 00:00:00 2001 From: sakaguchi Date: Fri, 29 May 2026 22:19:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20#4338=20=E3=80=90=E3=83=A1=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=80=91=E7=A2=BA=E8=AA=8D=E7=94=BB=E9=9D=A2=E3=81=A7?= =?UTF-8?q?=E9=80=81=E4=BF=A1=E6=99=82=E3=81=AB=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E3=81=A8=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=AB=E3=81=AA=E3=82=8B=E4=BB=B6=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/BcMail/element/mail_input.php | 2 +- .../bc-mail/src/Model/Table/MailMessagesTable.php | 10 +++++----- .../src/Service/Admin/MailFieldsAdminService.php | 2 +- .../TestCase/Controller/MailControllerTest.php | 15 ++++++++++----- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php b/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php index a1dca16235..7a6610a4f8 100755 --- a/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php +++ b/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php @@ -95,7 +95,7 @@ } /* 説明欄 */ - $isGroupValidComplate = in_array('VALID_GROUP_COMPLATE', explode(',', $field->valid_ex)); + $isGroupValidComplate = in_array('VALID_GROUP_COMPLATE', explode(',', (string) $field->valid_ex)); if(!$isGroupValidComplate) { echo $this->BcBaser->mailFormError("MailMessage." . $field->field_name); } diff --git a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php index 209b58d903..e4b3c1158a 100755 --- a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php +++ b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php @@ -252,7 +252,7 @@ protected function setupValidate(array $postData) // ### 拡張バリデーション if ($mailField->valid_ex && !empty($mailField->use_field)) { - $valids = explode(',', $mailField->valid_ex); + $valids = explode(',', (string) $mailField->valid_ex); foreach($valids as $valid) { $options = preg_split('/(?options); /** @@ -449,7 +449,7 @@ protected function _validGroupComplete(EntityInterface $entity) $dists = []; foreach($this->mailFields as $mailField) { // 対象フィールドがあれば、バリデートグループごとに配列に格納する - $valids = explode(',', $mailField->valid_ex); + $valids = explode(',', (string) $mailField->valid_ex); if (in_array('VALID_GROUP_COMPLATE', $valids)) { $dists[$mailField->group_valid][] = [ 'name' => $mailField->field_name, @@ -522,9 +522,9 @@ public function convertDatasToMail($data, $options) foreach($mailFields as $key => $value) { $fieldName = $value->field_name; - $value->before_attachment = strip_tags($value->before_attachment); - $value->after_attachment = str_replace(["
", "
"], "\n", strip_tags($value->after_attachment, "
")); - $value->head = str_replace(["
", "
"], "", strip_tags($value->head, "
")); + $value->before_attachment = strip_tags((string) $value->before_attachment); + $value->after_attachment = str_replace(["
", "
"], "\n", strip_tags((string) $value->after_attachment, "
")); + $value->head = str_replace(["
", "
"], "", strip_tags((string) $value->head, "
")); if ($value->no_send) { unset($message->{$fieldName}); } diff --git a/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php b/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php index 90380721cd..158a5a897e 100644 --- a/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php +++ b/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php @@ -88,7 +88,7 @@ public function getViewVarsForEdit(int $mailContentId, EntityInterface $mailFiel { /* @var \BcMail\Service\MailContentsService $mailContentsService */ $mailContentsService = $this->getService(MailContentsServiceInterface::class); - $mailField->valid_ex = explode(',', $mailField->valid_ex); + $mailField->valid_ex = explode(',', (string) $mailField->valid_ex); $mailContent = $mailContentsService->get($mailContentId); return [ 'mailContent' => $mailContent, diff --git a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php index c63052b3f3..c9bc5c15fa 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php @@ -151,7 +151,6 @@ public function testConfirm() */ public function testSubmit() { - $this->markTestIncomplete('このテストは未確認です'); //準備 $this->enableSecurityToken(); $this->enableCsrfToken(); @@ -159,7 +158,8 @@ public function testSubmit() SiteConfigFactory::make(['name' => 'email', 'value' => 'abc@gmail.com'])->persist(); SiteConfigFactory::make(['name' => 'admin-theme', 'value' => 'test theme'])->persist(); SiteFactory::make(['id' => 1])->persist(); - MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'sex'])->persist(); + MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'sex', 'valid' => 0, 'use_field' => 1])->persist(); + MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'name_1', 'valid' => 1, 'use_field' => 1])->persist(); ContentFactory::make(['id' => 1, 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1, 'url' => '/contact/', 'site_id' => 1, 'lft' => 1, 'rght' => 2])->persist(); MailContentFactory::make([ 'id' => 1, @@ -170,10 +170,15 @@ public function testSubmit() 'sender_1' => 't@gm.com' ])->persist(); + // 回帰テスト: バリデーションエラー時に 500 にならず確認画面を再表示する $this->session(['BcMail' => ['valid' => true]]); - $this->post('/contact/submit/', ['sex' => 1]); - $this->assertResponseCode(302); - $this->assertRedirect('/contact/thanks'); + $this->post('/contact/submit/', ['sex' => 1, 'name_1' => '']); + $this->assertResponseCode(200); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertNotNull($vars['mailContent']); + $this->assertNotNull($vars['mailFields']); + $this->assertNotNull($vars['mailMessage']); + $this->assertArrayHasKey('name_1', $vars['mailMessage']->getErrors()); } /**