From 9e049aff4b3cad95111856eec091b31e5e9ff4f1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 21 Mar 2026 10:23:00 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=A1=E3=83=BC=E3=83=AB=E3=83=95?= =?UTF-8?q?=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E5=90=8D=E3=81=ABMySQL?= =?UTF-8?q?=E4=BA=88=E7=B4=84=E8=AA=9E=E3=82=92=E7=99=BB=E9=8C=B2=E3=81=97?= =?UTF-8?q?=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AE=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E8=BF=BD=E5=8A=A0=20(#4332?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MailFieldsTable::validationDefault() に BcValidation::reserved() による 予約語チェックを追加。CustomFieldsTable と同様のバリデーションパターンを適用。 - field_name に reserved バリデーションルールを追加 - BcValidation プロバイダー (bc) を登録 - ユニットテストを追加(select, insert, update などの予約語をテスト) Co-authored-by: tera --- .../src/Model/Table/MailFieldsTable.php | 7 +++++ .../Model/Table/MailFieldsTableTest.php | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php index 0517cb85ea..bf2013ad25 100755 --- a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php +++ b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php @@ -58,6 +58,7 @@ public function initialize(array $config): void */ public function validationDefault(Validator $validator): Validator { + $validator->setProvider('bc', 'BaserCore\Model\Validation\BcValidation'); $validator ->integer('id') ->allowEmptyString('id', null, 'create'); @@ -80,6 +81,12 @@ public function validationDefault(Validator $validator): Validator 'rule' => 'duplicateMailField', 'provider' => 'table', 'message' => __d('baser_core', '既に登録のあるフィールド名です。') + ]]) + ->add('field_name', [ + 'reserved' => [ + 'rule' => ['reserved'], + 'provider' => 'bc', + 'message' => __d('baser_core', 'システム予約名称のため利用できません。') ]]); $validator ->scalar('type') diff --git a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php index 0950579a5a..e8b9d1e933 100755 --- a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php +++ b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php @@ -158,6 +158,35 @@ public function test_validationDefaultDuplicate() $this->assertEquals('既に登録のあるフィールド名です。', current($errors['field_name'])); } + /** + * test validationDefault reserved word check + * @dataProvider validationDefaultReservedDataProvider + */ + public function test_validationDefaultReserved($fieldName, $expected) + { + $validator = $this->MailFieldsTable->getValidator('default'); + $errors = $validator->validate([ + 'mail_content_id' => 999, + 'field_name' => $fieldName, + ]); + if ($expected) { + $this->assertArrayNotHasKey('reserved', $errors['field_name'] ?? []); + } else { + $this->assertArrayHasKey('reserved', $errors['field_name']); + $this->assertEquals('システム予約名称のため利用できません。', $errors['field_name']['reserved']); + } + } + + public static function validationDefaultReservedDataProvider() + { + return [ + ['test_field', true], + ['select', false], + ['insert', false], + ['update', false], + ]; + } + /** * コントロールソースを取得する */