Skip to content

Commit a9257d0

Browse files
committed
Fixed issue with spaces befor closing tag
Fixes paquettg#45
1 parent 80f5474 commit a9257d0

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ protected function clean($str)
358358
return $str;
359359
}
360360

361+
// remove white space before closing tags
362+
$str = mb_eregi_replace("'\s+>", "'>", $str);
363+
$str = mb_eregi_replace('"\s+>', '">', $str);
364+
361365
// clean out the \n\r
362366
$replace = ' ';
363367
if ($this->options->get('preserveLineBreaks')) {

tests/DomTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,11 @@ public function testMultipleSingleQuotes()
295295
$dom->load("<a title='Ain't this the best' href=\"http://www.example.com\">Hello</a>");
296296
$this->assertEquals("Ain't this the best", $dom->getElementsByTag('a')[0]->title);
297297
}
298+
299+
public function testBeforeClosingTag()
300+
{
301+
$dom = new Dom;
302+
$dom->load("<div class=\"stream-container \" > <div class=\"stream-item js-new-items-bar-container\"> </div> <div class=\"stream\">");
303+
$this->assertEquals("<div class=\"stream-container \"> <div class=\"stream-item js-new-items-bar-container\"> </div> <div class=\"stream\"></div></div>", (string) $dom);
304+
}
298305
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use PHPHtmlParser\Dom;
4+
5+
class PreserveLineBreaks extends PHPUnit_Framework_TestCase {
6+
7+
public function testPreserveLineBreakTrue()
8+
{
9+
$dom = new Dom;
10+
$dom->setOptions([
11+
'preserveLineBreaks' => true,
12+
]);
13+
$dom->load("<div class=\"stream-container \">
14+
<div class=\"stream-item js-new-items-bar-container\"> </div> <div class=\"stream\">");
15+
16+
$this->assertEquals("<div class=\"stream-container \">\n<div class=\"stream-item js-new-items-bar-container\"> </div> <div class=\"stream\"></div></div>", (string) $dom);
17+
}
18+
19+
public function testPreserveLineBreakBeforeClosingTag()
20+
{
21+
$dom = new Dom;
22+
$dom->setOptions([
23+
'preserveLineBreaks' => true,
24+
]);
25+
$dom->load("<div class=\"stream-container \"
26+
><div class=\"stream-item js-new-items-bar-container\"> </div> <div class=\"stream\">");
27+
28+
$this->assertEquals("<div class=\"stream-container \"><div class=\"stream-item js-new-items-bar-container\"> </div> <div class=\"stream\"></div></div>", (string) $dom);
29+
}
30+
}

0 commit comments

Comments
 (0)