Feature #20521 ยป 0011210.patch
t3lib/class.t3lib_div.php (Arbeitskopie) | ||
---|---|---|
}
|
||
/**
|
||
* Determines whether a string seems to be a valid regular expression.
|
||
*
|
||
* @param string $string: The string to be validated
|
||
* @param boolean $allowModifiers: Whether to allow modifiers (default: true)
|
||
* @return boolean Whether the string seems to be a valid regular expression
|
||
*/
|
||
public static function isValidRegularExpression($string, $allowModifiers = true) {
|
||
$result = false;
|
||
$pattern = '/^([^[:alnum:]\\\])(.+)\1' . ($allowModifiers ? '[imsxeADSUXJu]*$/' : '$/');
|
||
if (preg_match($pattern, $string, $matches)) {
|
||
// Checks whether there are unescaped delimiters in the body of the regular expression:
|
||
$delimiter = preg_quote($matches[1], '#');
|
||
$result = (preg_match('#(?<!\\\)' . $delimiter . '#', $matches[2]) ? false : true);
|
||
}
|
||
return $result;
|
||
}
|
||
/**
|
||
* Formats a string for output between <textarea>-tags
|
||
* All content outputted in a textarea form should be passed through this function
|
||
* Not only is the content htmlspecialchar'ed on output but there is also a single newline added in the top. The newline is necessary because browsers will ignore the first newline after <textarea> if that is the first character. Therefore better set it!
|
tests/t3lib/t3lib_div_testcase.php (Arbeitskopie) | ||
---|---|---|
$this->assertEquals('blogExample', t3lib_div::lcfirst('BlogExample'));
|
||
$this->assertEquals('blogexample', t3lib_div::lcfirst('blogexample'));
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidRegularExpression
|
||
*/
|
||
public function isValidRegularExpressionWithSlashes() {
|
||
$this->assertTrue(
|
||
t3lib_div::isValidRegularExpression('/(a|b|c)/i')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidRegularExpression
|
||
*/
|
||
public function isValidRegularExpressionWithHashes() {
|
||
$this->assertTrue(
|
||
t3lib_div::isValidRegularExpression('#(a|b|c)#i')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidRegularExpression
|
||
*/
|
||
public function isValidRegularExpressionUsingDifferentDelimiters() {
|
||
$this->assertFalse(
|
||
t3lib_div::isValidRegularExpression('#(a|b|c)/i')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidRegularExpression
|
||
*/
|
||
public function isValidRegularExpressionUsingWrongDelimiters() {
|
||
$this->assertFalse(
|
||
t3lib_div::isValidRegularExpression('A(a|b|c)Ai')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidRegularExpression
|
||
*/
|
||
public function isValidRegularExpressionWithUnescapedDelimiter() {
|
||
$this->assertFalse(
|
||
t3lib_div::isValidRegularExpression('/(a/b/c)/i')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidRegularExpression
|
||
*/
|
||
public function isValidRegularExpressionWithEscapedDelimiter() {
|
||
$this->assertTrue(
|
||
t3lib_div::isValidRegularExpression('/(a\/b\/c)/i')
|
||
);
|
||
}
|
||
}
|
||
?>
|