Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix-parse-links' into fix-parse-…
Browse files Browse the repository at this point in the history
…links
  • Loading branch information
Claudio-Emmolo committed Jun 17, 2024
2 parents ec6f429 + 77649c2 commit cd92474
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Helpers/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public static function parseAllLinks(?string $content): string
protected static function parseLink(string $content, array $linksToCheck, string $rel)
{
return preg_replace_callback('/<a\s+([^>]+)>/', function ($matches) use ($linksToCheck, $rel) {
if (!preg_match('/rel="/', $matches[0])) {
if (! preg_match('/rel="/', $matches[0])) {
preg_match('/href="([^"]*)"/', $matches[1], $hrefMatches);
$link = $hrefMatches[1];
foreach ($linksToCheck as $linkToCheck) {
if (@preg_match($linkToCheck, $link)) {
if (preg_match($linkToCheck, $link)) {
return str_replace('<a ' . $matches[1], '<a ' . $matches[1] . ' rel="' . $rel . '"', $matches[0]);
return str_replace('<a '.$matches[1], '<a '.$matches[1].' rel="'.$rel.'"', $matches[0]);
}
} else {
if (strpos($link, $linkToCheck) === 0) {
return str_replace('<a ' . $matches[1], '<a ' . $matches[1] . ' rel="' . $rel . '"', $matches[0]);
return str_replace('<a '.$matches[1], '<a '.$matches[1].' rel="'.$rel.'"', $matches[0]);
}
}
}
Expand Down

0 comments on commit cd92474

Please sign in to comment.