Show when a banned regex is invalid
This commit is contained in:
parent
63a619d295
commit
824d078ece
@ -69,24 +69,27 @@ xanax
|
|||||||
$sb = new SetupBlock("Banned Phrases");
|
$sb = new SetupBlock("Banned Phrases");
|
||||||
$sb->add_label("One per line, lines that start with slashes are treated as regex<br/>");
|
$sb->add_label("One per line, lines that start with slashes are treated as regex<br/>");
|
||||||
$sb->add_longtext_option("banned_words");
|
$sb->add_longtext_option("banned_words");
|
||||||
|
$failed = array();
|
||||||
|
foreach($this->get_words() as $word) {
|
||||||
|
if($word[0] == '/') {
|
||||||
|
if(preg_match($word, "") === false) {
|
||||||
|
$failed[] = $word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($failed) {
|
||||||
|
$sb->add_label("Failed regexes: ".join(", ", $failed));
|
||||||
|
}
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function test_text($comment, $ex) {
|
private function test_text($comment, $ex) {
|
||||||
global $config;
|
|
||||||
|
|
||||||
$banned = $config->get_string("banned_words");
|
|
||||||
$comment = strtolower($comment);
|
$comment = strtolower($comment);
|
||||||
|
|
||||||
foreach(explode("\n", $banned) as $word) {
|
foreach($this->get_words() as $word) {
|
||||||
$word = trim(strtolower($word));
|
if($word[0] == '/') {
|
||||||
if(strlen($word) == 0) {
|
|
||||||
// line is blank
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if($word[0] == '/') {
|
|
||||||
// lines that start with slash are regex
|
// lines that start with slash are regex
|
||||||
if(preg_match($word, $comment)) {
|
if(preg_match($word, $comment) === 1) {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +102,23 @@ xanax
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_words() {
|
||||||
|
global $config;
|
||||||
|
$words = array();
|
||||||
|
|
||||||
|
$banned = $config->get_string("banned_words");
|
||||||
|
foreach(explode("\n", $banned) as $word) {
|
||||||
|
$word = trim(strtolower($word));
|
||||||
|
if(strlen($word) == 0) {
|
||||||
|
// line is blank
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$words[] = $word;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $words;
|
||||||
|
}
|
||||||
|
|
||||||
public function get_priority() {return 30;}
|
public function get_priority() {return 30;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user