diff --git a/src/Middleware/RemoveQuotes.php b/src/Middleware/RemoveQuotes.php index ce6ce7b..b5132bb 100644 --- a/src/Middleware/RemoveQuotes.php +++ b/src/Middleware/RemoveQuotes.php @@ -2,10 +2,14 @@ namespace RenatoMarinho\LaravelPageSpeed\Middleware; +use RenatoMarinho\LaravelPageSpeed\Entities\HtmlSpecs; + class RemoveQuotes extends PageSpeed { public function apply($buffer) { + $buffer = $this->replaceInsideHtmlTags(HtmlSpecs::voidElements(), '/\/>/', '>', $buffer); + $replace = [ '/ src="(.\S*?)"/' => ' src=$1', '/ width="(.\S*?)"/' => ' width=$1', @@ -16,7 +20,6 @@ public function apply($buffer) '/ border="(.\S*?)"/' => ' border=$1', '/ crossorigin="(.\S*?)"/' => ' crossorigin=$1', '/ type="(.\S*?)"/' => ' type=$1', - '/\/>/' => '>', ]; return $this->replace($replace, $buffer); diff --git a/tests/Boilerplate/index.html b/tests/Boilerplate/index.html index 676e5ab..9633647 100644 --- a/tests/Boilerplate/index.html +++ b/tests/Boilerplate/index.html @@ -41,6 +41,12 @@

Test Background Image

+ + + + + + diff --git a/tests/Middleware/RemoveQuotesTest.php b/tests/Middleware/RemoveQuotesTest.php index 2915611..d351c59 100644 --- a/tests/Middleware/RemoveQuotesTest.php +++ b/tests/Middleware/RemoveQuotesTest.php @@ -7,6 +7,15 @@ class RemoveQuotesTest extends TestCase { + protected $response; + + public function setUp(): void + { + parent::setUp(); + + $this->response = $this->middleware->handle($this->request, $this->getNext()); + } + protected function getMiddleware() { $this->middleware = new RemoveQuotes(); @@ -14,15 +23,19 @@ protected function getMiddleware() public function testRemoveQuotes() { - $response = $this->middleware->handle($this->request, $this->getNext()); - - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); - $this->assertStringContainsString('', $response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); + } + + public function testWontRemoveTrailingSlashesOfNonVoidElements() + { + $this->assertStringContainsString('', $this->response->getContent()); + $this->assertStringContainsString('', $this->response->getContent()); } }