diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php index 23b5be65d567..4a68cee65994 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php @@ -1,5 +1,7 @@ addError( $this->translateErrorMessage( 'validator.text.notvalid', diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php index 34ceb1c621e1..2c2c4e03bb56 100644 --- a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php @@ -36,38 +36,67 @@ public function setup(): void ->getMock(); } - /** - * @test - */ - public function textValidatorReturnsNoErrorForASimpleString(): void - { - self::assertFalse($this->validator->validate('this is a very simple string')->hasErrors()); - } - - /** - * @test - */ - public function textValidatorAllowsTheNewLineCharacter(): void - { - $sampleText = 'Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och. nVu dan durch jéngt gréng, ze rou Monn voll stolz. nKe kille Minutt d\'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zënter, Welt Ronn grousse der ke. Wou fond eraus Wisen am. Hu dénen d\'Gaassen eng, eng am virun geplot d\'Lëtzebuerger, get botze rëscht Blieder si. Dat Dauschen schéinste Milliounen fu. Ze riede méngem Keppchen déi, si gét fergiess erwaacht, räich jéngt duerch en nun. Gëtt Gaas d\'Vullen hie hu, laacht Grénge der dé. Gemaacht gehéiert da aus, gutt gudden d\'wäiss mat wa.'; - self::assertFalse($this->validator->validate($sampleText)->hasErrors()); - } - - /** - * @test - */ - public function textValidatorAllowsCommonSpecialCharacters(): void + public function isValidDataProvider(): array { - $sampleText = '3% of most people tend to use semikolae; we need to check & allow that. And hashes (#) are not evil either, nor is the sign called \'quote\'.'; - self::assertFalse($this->validator->validate($sampleText)->hasErrors()); + return [ + 'a simple string' => [ + false, // expectation: no error + 'this is a very simple string', // test string + ], + 'allow new line character' => [ + false, + 'Ierd Frot uechter mä get, Kirmesdag' . chr(10) . 'Ke kille Minutt', + ], + 'allow single quote' => [ + false, + 'foo \' bar', + ], + 'allow double quote' => [ + false, + 'foo " bar', + ], + 'slash' => [ + false, + 'foo/bar', + ], + 'slash with closing angle bracket' => [ + false, + 'foo/>bar', + ], + 'closing angle bracket without opening angle bracket' => [ + false, + '>foo', + ], + 'common special characters' => [ + false, + '3% of most people tend to use semikolae; we need to check & allow that. And hashes (#) are not evil either, nor is the sign called \'quote\'.', + ], + 'nul byte' => [ + true, + 'foo' . chr(0) . 'bar', + ], + 'a string with html' => [ + true, + 'a nice text', + ], + 'not closed html' => [ + true, + 'bar', + ], + 'opening angle bracket' => [ + true, + 'validator->validate('a nice text')->hasErrors()); + self::assertSame($expectation, $this->validator->validate($testString)->hasErrors()); } /**