Skip to content

Commit d9237f4

Browse files
Merge pull request #125 from lucasMesquitaBorges/fix-remove-quotes-whitespaces
Fix remove quotes when attributes contains whitespaces
2 parents c09b69f + 4505d4f commit d9237f4

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/Middleware/RemoveQuotes.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ class RemoveQuotes extends PageSpeed
77
public function apply($buffer)
88
{
99
$replace = [
10-
'/ src="(.*?)"/' => ' src=$1',
11-
'/ width="(.*?)"/' => ' width=$1',
12-
'/ height="(.*?)"/' => ' height=$1',
13-
'/ name="(.*?)"/' => ' name=$1',
14-
'/ charset="(.*?)"/' => ' charset=$1',
15-
'/ align="(.*?)"/' => ' align=$1',
16-
'/ border="(.*?)"/' => ' border=$1',
17-
'/ crossorigin="(.*?)"/' => ' crossorigin=$1',
18-
'/ type="(.*?)"/' => ' type=$1',
10+
'/ src="(.\S*?)"/' => ' src=$1',
11+
'/ width="(.\S*?)"/' => ' width=$1',
12+
'/ height="(.\S*?)"/' => ' height=$1',
13+
'/ name="(.\S*?)"/' => ' name=$1',
14+
'/ charset="(.\S*?)"/' => ' charset=$1',
15+
'/ align="(.\S*?)"/' => ' align=$1',
16+
'/ border="(.\S*?)"/' => ' border=$1',
17+
'/ crossorigin="(.\S*?)"/' => ' crossorigin=$1',
18+
'/ type="(.\S*?)"/' => ' type=$1',
1919
'/\/>/' => '>',
2020
];
2121

tests/Boilerplate/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ <h1>Test Background Image</h1>
3030
</div>
3131
<img src="http://emblemsbf.com/img/18346.jpg" width="250" style="height:300px; padding:10px" />
3232

33+
<img src="tile whitespace.png" width="250" style="height:300px; padding:10px"/>
34+
3335
<form method="get" class="form" style="display:block;border:1px solid red;">
3436

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

41+
<input type="text" name="name with spaces" value="name with spaces" width="100%">
42+
3943
<select style="height:300px; padding:10px">
4044
<option selected="selected" class="selected" style="cursor: default">Item</option>
4145
<option selected=selected>Item</option>

tests/Middleware/RemoveQuotesTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ public function testRemoveQuotes()
2222
$this->assertContains('<img src=http://emblemsbf.com/img/18346.jpg width=250 style="height:300px; padding:10px" >', $response->getContent());
2323
$this->assertContains('<img src=/images/1000coin.png>', $response->getContent());
2424
$this->assertContains('<vue-component :src="\'src\'" :type="\'type\'" :width="200"></vue-component>', $response->getContent());
25+
$this->assertContains('<img src="tile whitespace.png" width=250 style="height:300px; padding:10px">', $response->getContent());
26+
$this->assertContains('<input type=text name="name with spaces" value="name with spaces" width=100%>', $response->getContent());
2527
}
2628
}

0 commit comments

Comments
 (0)