mirror of https://github.com/MISP/MISP
fix: [internal] Faster RegexpBehavior
parent
b5b26455f0
commit
21afe562ef
|
@ -9,7 +9,7 @@ class RegexpBehavior extends ModelBehavior
|
|||
{
|
||||
private $__allRegexp = null;
|
||||
|
||||
public $excluded_types = array('sigma', 'float');
|
||||
const EXCLUDED_TYPES = array('sigma', 'float');
|
||||
|
||||
/**
|
||||
* replace the current value according to the regexp rules, or block blocklisted regular expressions
|
||||
|
@ -21,21 +21,24 @@ class RegexpBehavior extends ModelBehavior
|
|||
*/
|
||||
public function runRegexp(Model $Model, $type, $value)
|
||||
{
|
||||
if (in_array($type, $this->excluded_types)) {
|
||||
if (in_array($type, self::EXCLUDED_TYPES, true)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($this->__allRegexp === null) {
|
||||
$regexp = new Regexp();
|
||||
$this->__allRegexp = $regexp->find('all', array('order' => 'id ASC'));
|
||||
$this->__allRegexp = array_column($regexp->find('all', [
|
||||
'order' => 'id ASC',
|
||||
'fields' => ['type', 'regexp', 'replacement'],
|
||||
]), 'Regexp');
|
||||
}
|
||||
|
||||
foreach ($this->__allRegexp as $regexp) {
|
||||
if ($regexp['Regexp']['type'] === 'ALL' || $regexp['Regexp']['type'] === $type) {
|
||||
if (!empty($regexp['Regexp']['replacement']) && !empty($regexp['Regexp']['regexp'])) {
|
||||
$value = preg_replace($regexp['Regexp']['regexp'], $regexp['Regexp']['replacement'], $value);
|
||||
if ($regexp['type'] === 'ALL' || $regexp['type'] === $type) {
|
||||
if (!empty($regexp['replacement']) && !empty($regexp['regexp'])) {
|
||||
$value = preg_replace($regexp['regexp'], $regexp['replacement'], $value);
|
||||
}
|
||||
if (empty($regexp['Regexp']['replacement']) && preg_match($regexp['Regexp']['regexp'], $value)) {
|
||||
if (empty($regexp['replacement']) && preg_match($regexp['regexp'], $value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5638,7 +5638,7 @@ class Event extends AppModel
|
|||
} else {
|
||||
$attribute_type = $attribute['type'];
|
||||
if (empty($attribute['category'])) {
|
||||
$attribute['category'] = $this->Attribute->typedefinitions[$attribute_type]['default_category'];
|
||||
$attribute['category'] = $this->Attribute->typeDefinitions[$attribute_type]['default_category'];
|
||||
}
|
||||
}
|
||||
if (!isset($attribute['to_ids'])) {
|
||||
|
|
Loading…
Reference in New Issue