Skip to content

Commit

Permalink
Merge pull request #83 from sandstein/issue_82
Browse files Browse the repository at this point in the history
Masks and unmasks angle brackets inside quotes to allow them when gen…
  • Loading branch information
jissereitsma authored Dec 4, 2024
2 parents 4f52905 + bdda91d commit 4d36e40
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Util/HtmlReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function replace(string $html): string
*/
private function replaceImageTags(string $html): string
{
$html = $this->maskAngleBracketsInsideQuotes($html);
$document = $this->domUtils->htmlToDOMDocument($html);
$images = $document->getElementsByTagName('img');
foreach ($images as $image) {
Expand All @@ -98,7 +99,7 @@ private function replaceImageTags(string $html): string
}
}

return $html;
return $this->unmaskAngleBracketsInsideQuotes($html);
}

/**
Expand Down Expand Up @@ -315,4 +316,26 @@ private function getAllowedSrcAttributes(): array
':data-src',
];
}

/**
* Masks angle brackets inside double quotes
*
* @param string $html
* @return string
*/
private function maskAngleBracketsInsideQuotes(string $html): string
{
return preg_replace('/"([^"]+)>([^"]+)"/', '"$1>$2"', $html);
}

/**
* Unmasks the above masked angle brackets
*
* @param string $html
* @return string
*/
private function unmaskAngleBracketsInsideQuotes(string $html): string
{
return preg_replace('/"([^"]+)>([^"]+)"/', '"$1>$2"', $html);
}
}

0 comments on commit 4d36e40

Please sign in to comment.