Skip to content

Commit

Permalink
[Core] Better phoneNumber & email content filter
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Aug 19, 2022
1 parent 782cf20 commit abf74c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/Component/EntityFilter/Filter/Email.php
Expand Up @@ -19,13 +19,17 @@ public function apply($propertyValue): string

public function convertEmail(string $body): string
{
$rgx = '/ ([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}) /i';
$rgx = '/ ([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})( |\.<\/|\. |$)/i';

\Safe\preg_match_all($rgx, $body, $matches);

$nbrMatch = \count($matches[0]);
for ($k = 0; $k < $nbrMatch; ++$k) {
$body = ' '.str_replace($matches[0][$k], $this->renderEncodedMail($matches[1][$k]), $body).' ';
$body = str_replace(
$matches[0][$k],
' '.$this->renderEncodedMail($matches[1][$k]).$matches[2][$k],
$body
);
}

return $body;
Expand Down
Expand Up @@ -19,15 +19,15 @@ public function apply($propertyValue): string

private function convertPhoneNumber(string $body): string
{
$rgx = '/ (?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4} /iU';
$rgx = '/ (?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}(?P<after> |\.<\/|\. |$)/iU';
\Safe\preg_match_all($rgx, $body, $matches);

if (! isset($matches[0])) {
return $body;
}

foreach ($matches[0] as $m) {
$body = str_replace($m, $this->renderPhoneNumber($m), $body);
dump($matches);
foreach ($matches[0] as $k => $m) {
$body = str_replace($m, ' '.$this->renderPhoneNumber(trim($m)).$matches['after'][$k], $body);
}

return $body;
Expand Down
@@ -1 +1 @@
<span class=nojs>{{ mail_readable|raw }} </span><span class="cea hidden {{ class ? ' ' ~ class : '' }}">{{ mail_encoded }}</span>
<span class=nojs>{{ mail_readable|raw }}</span><span class="cea hidden {{ class ? ' ' ~ class : '' }}"> {{ mail_encoded }}</span>

0 comments on commit abf74c5

Please sign in to comment.