Skip to content

Commit

Permalink
Merge pull request #125 from lucasMesquitaBorges/fix-remove-quotes-wh…
Browse files Browse the repository at this point in the history
…itespaces

Fix remove quotes when attributes contains whitespaces
  • Loading branch information
lucasMesquitaBorges authored May 2, 2020
2 parents c09b69f + 4505d4f commit d9237f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Middleware/RemoveQuotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class RemoveQuotes extends PageSpeed
public function apply($buffer)
{
$replace = [
'/ src="(.*?)"/' => ' src=$1',
'/ width="(.*?)"/' => ' width=$1',
'/ height="(.*?)"/' => ' height=$1',
'/ name="(.*?)"/' => ' name=$1',
'/ charset="(.*?)"/' => ' charset=$1',
'/ align="(.*?)"/' => ' align=$1',
'/ border="(.*?)"/' => ' border=$1',
'/ crossorigin="(.*?)"/' => ' crossorigin=$1',
'/ type="(.*?)"/' => ' type=$1',
'/ src="(.\S*?)"/' => ' src=$1',
'/ width="(.\S*?)"/' => ' width=$1',
'/ height="(.\S*?)"/' => ' height=$1',
'/ name="(.\S*?)"/' => ' name=$1',
'/ charset="(.\S*?)"/' => ' charset=$1',
'/ align="(.\S*?)"/' => ' align=$1',
'/ border="(.\S*?)"/' => ' border=$1',
'/ crossorigin="(.\S*?)"/' => ' crossorigin=$1',
'/ type="(.\S*?)"/' => ' type=$1',
'/\/>/' => '>',
];

Expand Down
4 changes: 4 additions & 0 deletions tests/Boilerplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ <h1>Test Background Image</h1>
</div>
<img src="http://emblemsbf.com/img/18346.jpg" width="250" style="height:300px; padding:10px" />

<img src="tile whitespace.png" width="250" style="height:300px; padding:10px"/>

<form method="get" class="form" style="display:block;border:1px solid red;">

<input type="text" disabled="true" value="teste" width="100%">
<input type="text" disabled="true">
<input style="border:1px solid red" type="text" disabled=true>

<input type="text" name="name with spaces" value="name with spaces" width="100%">

<select style="height:300px; padding:10px">
<option selected="selected" class="selected" style="cursor: default">Item</option>
<option selected=selected>Item</option>
Expand Down
2 changes: 2 additions & 0 deletions tests/Middleware/RemoveQuotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public function testRemoveQuotes()
$this->assertContains('<img src=http://emblemsbf.com/img/18346.jpg width=250 style="height:300px; padding:10px" >', $response->getContent());
$this->assertContains('<img src=/images/1000coin.png>', $response->getContent());
$this->assertContains('<vue-component :src="\'src\'" :type="\'type\'" :width="200"></vue-component>', $response->getContent());
$this->assertContains('<img src="tile whitespace.png" width=250 style="height:300px; padding:10px">', $response->getContent());
$this->assertContains('<input type=text name="name with spaces" value="name with spaces" width=100%>', $response->getContent());
}
}

0 comments on commit d9237f4

Please sign in to comment.