From: jenkins-bot Date: Thu, 19 Sep 2019 08:03:33 +0000 (+0000) Subject: Merge "StringUtils: Add a utility for checking if a string is a valid regex" X-Git-Tag: 1.34.0-rc.0~159 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=a1ef77b2d80830fbcb617a83961d78cff9d6e384;hp=2501d1dedfbdaba981cea49ff7b67fda0926d822 Merge "StringUtils: Add a utility for checking if a string is a valid regex" --- diff --git a/includes/libs/StringUtils.php b/includes/libs/StringUtils.php index 51d108168a..19dd8fe4d3 100644 --- a/includes/libs/StringUtils.php +++ b/includes/libs/StringUtils.php @@ -1,4 +1,7 @@ [ $PASS, "\xef\xbf\xbf" ], ]; } + + /** + * @param strin $input + * @param bool $expected + * @dataProvider provideRegexps + * @covers StringUtils::isValidRegex + */ + public function testIsValidRegex( $input, $expected ) { + $this->assertSame( $expected, StringUtils::isValidRegex( $input ) ); + } + + /** + * Data provider for testValidRegex + */ + public static function provideRegexps() { + return [ + [ 'foo', false ], + [ '/foo/', true ], + [ '//', true ], + [ '/(foo/', false ], + [ '!(f[o]{2})!', true ], + [ '/foo\/', false ] + ]; + } }