Skip to content

Commit

Permalink
new filter remove_quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomarinho committed Sep 23, 2017
1 parent 2989dfc commit e450d72
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ protected $middleware = [
<td><strong>Description</strong></td>
<td><strong>Available</strong></td>
<tr>
<tr>
<td>remove_quotes</td>
<td>Removes unnecessary quotes in HTML tags</td>
<td>YES</td>
<tr>
<tr>
<td>trim_urls</td>
<td>Removes unnecessary prefixes from URLs</td>
Expand Down Expand Up @@ -194,11 +199,6 @@ protected $middleware = [
<td>Instruments the page, inlines its critical CSS at the top, and lazily loads the rest</td>
<td>NO</td>
<tr>
<tr>
<td>remove_quotes</td>
<td>Removes unnecessary quotes in HTML tags</td>
<td>NO</td>
<tr>
<tr>
<td>resize_mobile_images</td>
<td>Just like inline_preview_images, but uses smaller placeholder images for mobile browsers</td>
Expand Down
29 changes: 16 additions & 13 deletions src/Middleware/RemoveQuotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

namespace RenatoMarinho\LaravelPageSpeed\Middleware;

use Closure;

class RemoveQuotes
class RemoveQuotes extends PageSpeed
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/

public function handle($request, Closure $next)
public function apply($buffer)
{
}
$replace = [
'/src="(.*?)"/' => 'src=$1',
'/width="(.*?)"/' => 'width=$1',
'/height="(.*?)"/' => 'height=$1',
'/name="(.*?)"/' => 'name=$1',
'/charset="(.*?)"/' => 'charset=$1',
'/href="(.*?)"/' => 'href=$1',
'/align="(.*?)"/' => 'align=$1',
'/border="(.*?)"/' => 'border=$1',
'/crossorigin="(.*?)"/' => 'crossorigin=$1',
'/rel="(.*?)"/' => 'rel=$1',
];

return $this->replace($replace, $buffer);
}
}
2 changes: 1 addition & 1 deletion tests/Middleware/RemoveCommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments;
use RenatoMarinho\LaravelPageSpeed\Test\TestCase;

class CollapseWhitespaceTest extends TestCase
class RemoveCommentsTest extends TestCase
{
public $middleware;

Expand Down
12 changes: 6 additions & 6 deletions tests/Middleware/RemoveQuotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

namespace RenatoMarinho\LaravelPageSpeed\Test\Middleware;

use RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls;
use RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes;
use RenatoMarinho\LaravelPageSpeed\Test\TestCase;

class TrimUrlsTest extends TestCase
class RemoveQuotesTest extends TestCase
{
public $middleware;

public function getMiddleware()
{
$this->middleware = new TrimUrls();
$this->middleware = new RemoveQuotes();
}

public function testApply()
{
$html = $this->middleware->apply($this->html);

$this->assertNotContains("https://", $html);
$this->assertNotContains("http://", $html);
$this->assertContains("//code.jquery.com/jquery-3.2.1.min.js", $html);
$this->assertContains('<link rel=apple-touch-icon href=icon.png>', $html);
$this->assertContains('<meta charset=utf-8>', $html);
$this->assertContains('<img src=http://emblemsbf.com/img/18346.jpg width=250 style="height:300px; padding:10px" />', $html);
}
}

0 comments on commit e450d72

Please sign in to comment.