mirror of https://github.com/MISP/MISP
chg: [internal] Faster freetext parsing
parent
7f935f4cec
commit
c2811888e4
|
@ -308,14 +308,13 @@ class ComplexTypeTool
|
||||||
*/
|
*/
|
||||||
private function parseFreetext($input)
|
private function parseFreetext($input)
|
||||||
{
|
{
|
||||||
$input = str_replace("\xc2\xa0", ' ', $input); // non breaking space to normal space
|
// convert non breaking space to normal space and all unicode chars from "other" category
|
||||||
$input = preg_replace('/\p{C}+/u', ' ', $input);
|
$input = preg_replace("/\p{C}+|\xc2\xa0/u", ' ', $input);
|
||||||
$iocArray = preg_split("/\r\n|\n|\r|\s|\s+|,|\<|\>|;/", $input);
|
$iocArray = preg_split("/\r\n|\n|\r|\s|\s+|,|<|>|;/", $input);
|
||||||
|
|
||||||
preg_match_all('/\"([^\"]+)\"/', $input, $matches);
|
preg_match_all('/\"([^\"]+)\"/', $input, $matches);
|
||||||
foreach ($matches[1] as $match) {
|
array_push($iocArray, ...$matches[1]);
|
||||||
$iocArray[] = $match;
|
|
||||||
}
|
|
||||||
return $iocArray;
|
return $iocArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -527,10 +527,31 @@ EOT;
|
||||||
public function testCheckFreeTextNonBreakableSpace(): void
|
public function testCheckFreeTextNonBreakableSpace(): void
|
||||||
{
|
{
|
||||||
$complexTypeTool = new ComplexTypeTool();
|
$complexTypeTool = new ComplexTypeTool();
|
||||||
|
|
||||||
$results = $complexTypeTool->checkFreeText("127.0.0.1\xc2\xa0127.0.0.2");
|
$results = $complexTypeTool->checkFreeText("127.0.0.1\xc2\xa0127.0.0.2");
|
||||||
$this->assertCount(2, $results);
|
$this->assertCount(2, $results);
|
||||||
$this->assertEquals('127.0.0.1', $results[0]['value']);
|
$this->assertEquals('127.0.0.1', $results[0]['value']);
|
||||||
$this->assertEquals('ip-dst', $results[0]['default_type']);
|
$this->assertEquals('ip-dst', $results[0]['default_type']);
|
||||||
|
|
||||||
|
$results = $complexTypeTool->checkFreeText("127.0.0.1\xc2\xa0\xc2\xa0127.0.0.2");
|
||||||
|
$this->assertCount(2, $results);
|
||||||
|
$this->assertEquals('127.0.0.1', $results[0]['value']);
|
||||||
|
$this->assertEquals('ip-dst', $results[0]['default_type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCheckFreeTextControlCharToSpace(): void
|
||||||
|
{
|
||||||
|
$complexTypeTool = new ComplexTypeTool();
|
||||||
|
|
||||||
|
$results = $complexTypeTool->checkFreeText("127.0.0.1\x1d127.0.0.2");
|
||||||
|
$this->assertCount(2, $results);
|
||||||
|
$this->assertEquals('127.0.0.1', $results[0]['value']);
|
||||||
|
$this->assertEquals('ip-dst', $results[0]['default_type']);
|
||||||
|
|
||||||
|
$results = $complexTypeTool->checkFreeText("127.0.0.1\x1d\x1d127.0.0.2");
|
||||||
|
$this->assertCount(2, $results);
|
||||||
|
$this->assertEquals('127.0.0.1', $results[0]['value']);
|
||||||
|
$this->assertEquals('ip-dst', $results[0]['default_type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckFreeTextQuoted(): void
|
public function testCheckFreeTextQuoted(): void
|
||||||
|
|
Loading…
Reference in New Issue