Skip to content

Commit

Permalink
Fixes #3461 Badword Filter Enhancement (2) (#3489)
Browse files Browse the repository at this point in the history
* badword filter enhancement

* Filter bad words in text wrapped with url
  • Loading branch information
effone authored and euantorano committed Jan 5, 2019
1 parent dd8b2fa commit 101f2d5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions inc/class_parser.php
Expand Up @@ -679,9 +679,9 @@ function generate_regex($bad_word = "")
return;
}

// Neutralize multiple adjacent wildcards and generate pattern
$ptrn = array('/\*\++/', '/\++\*/', '/\*+/');
$rplc = array('*', '*', '[^\s\n]*');
// Neutralize escape character, regex operators, multiple adjacent wildcards and generate pattern
$ptrn = array('/\\\\/', '/([\[\^\$\.\|\?\(\)\{\}]{1})/', '/\*\++/', '/\++\*/', '/\*+/');
$rplc = array('\\\\\\\\','\\\\${1}', '*', '*', '[^\s\n]*');
$bad_word = preg_replace($ptrn, $rplc, $bad_word);

// Count + and generate pattern
Expand All @@ -707,7 +707,7 @@ function generate_regex($bad_word = "")
$trap .= '[^\s\n]{'.($plus-1).'}';
}

return '\b'.$trap.'\b';
return '[\b\B]{0}'.$trap.'[\b\B]{0}';
}

/**
Expand Down Expand Up @@ -1133,9 +1133,7 @@ function mycode_parse_url($url, $name="")

// Fix some entities in URLs
$url = $this->encode_url($url);


$name = preg_replace("#&\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode
$name = $this->parse_badwords(preg_replace("#&\#([0-9]+);#si", "&#$1;", $name)); // Fix & but allow unicode, filter bad words

eval("\$mycode_url = \"".$templates->get("mycode_url", 1, 0)."\";");
return $mycode_url;
Expand Down

0 comments on commit 101f2d5

Please sign in to comment.