Skip to content

Commit

Permalink
Added masterminds/html5, which should solve the user-input and HTML5 …
Browse files Browse the repository at this point in the history
…issues
  • Loading branch information
Roelof Roos committed Mar 6, 2020
1 parent 0ca8a5d commit df8ab3f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"illuminate/contracts": "^5.3 | ^6.0 | ^7.0",
"illuminate/support": "^5.3 | ^6.0 | ^7.0",
"illuminate/mail": "^5.3 | ^6.0 | ^7.0 | ^8.0",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5",
"masterminds/html5": "^2.0"
},
"require-dev": {
"php": ">=7.0",
Expand Down
8 changes: 5 additions & 3 deletions src/Listeners/SwiftEmbedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Eduardokum\LaravelMailAutoEmbed\Embedder\Base64Embedder;
use Eduardokum\LaravelMailAutoEmbed\Embedder\Embedder;
use Eduardokum\LaravelMailAutoEmbed\Models\EmbeddableEntity;
use Masterminds\HTML5;
use ReflectionClass;
use Swift_Events_SendEvent;
use Swift_Events_SendListener;
Expand Down Expand Up @@ -61,8 +62,9 @@ private function attachImages()
$body = $this->message->getBody();

// Parse document
$document = new DOMDocument();
if (!$document->loadHTML($body)) {
$parser = new HTML5();
$document = $parser->loadHTML($body);
if (!$document) {
// Cannot read
return;
}
Expand All @@ -71,7 +73,7 @@ private function attachImages()
$this->attachImagesToDom($document);

// Replace body
$this->message->setBody($document->saveHTML());
$this->message->setBody($parser->saveHTML($document));
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/Traits/InteractsWithSwift.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ protected function handleBeforeSendPerformedEvent($libraryFile, $options)
protected function assertEmailImageTags($expectations, $body)
{
foreach ($expectations as $comment => $src) {
// Gimmick of using a DOMDocument parser
$src = str_replace('\\', '%5C', \htmlspecialchars($src));

// Fix for PHPUnit <8.0
// phpcs:ignore Generic.Files.LineLength.TooLong
$method = \method_exists($this, 'assertStringContainsString') ? 'assertStringContainsString' : 'assertContains';
Expand Down

0 comments on commit df8ab3f

Please sign in to comment.