Skip to content

Commit 1a11a7e

Browse files
committed
Fixed bug when no attribute tags are last tag (with out space).
fixes paquettg#16
1 parent f400ff7 commit 1a11a7e

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ protected function clean($str)
372372
return $str;
373373
}
374374

375-
/**
375+
/**<?php
376376
* Attempts to parse the html in content.
377377
*/
378378
protected function parse()
@@ -550,7 +550,10 @@ protected function parseTag()
550550
'value' => null,
551551
'doubleQuote' => true,
552552
];
553-
$this->content->rewind(1);
553+
if ($this->content->char() != '>')
554+
{
555+
$this->content->rewind(1);
556+
}
554557
}
555558
}
556559

tests/DomTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ public function testLoadClosingTagClearSelfClosingTag()
123123
$this->assertEquals('<br><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></br>', $dom->find('div', 0)->innerHtml);
124124
}
125125

126+
public function testLoadNoValueAttribute()
127+
{
128+
$dom = new Dom;
129+
$dom->load('<div class="content"><div class="grid-container" ui-view>Main content here</div></div>');
130+
$this->assertEquals('<div class="content"><div class="grid-container" ui-view>Main content here</div></div>', $dom->innerHtml);
131+
}
132+
133+
public function testLoadNoValueAttributeBefore()
134+
{
135+
$dom = new Dom;
136+
$dom->load('<div class="content"><div ui-view class="grid-container">Main content here</div></div>');
137+
$this->assertEquals('<div class="content"><div ui-view class="grid-container">Main content here</div></div>', $dom->innerHtml);
138+
}
139+
126140
public function testLoadUpperCase()
127141
{
128142
$dom = new Dom;

tests/Node/HtmlTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,29 @@ public function testOuterHtmlMagic()
224224
$this->assertEquals('<div class="all"><a href=\'http://google.com\'>link</a><br /></div>', $parent->outerHtml);
225225
}
226226

227+
public function testOuterHtmlNoValueAttribute()
228+
{
229+
$parent = new HtmlNode('div');
230+
$parent->setAttribute('class', [
231+
'value' => 'all',
232+
'doubleQuote' => true,
233+
]);
234+
$childa = new HtmlNode('a');
235+
$childa->setAttribute('href', [
236+
'value' => 'http://google.com',
237+
'doubleQuote' => false,
238+
]);
239+
$childa->setAttribute('ui-view', null);
240+
$childbr = new HtmlNode('br');
241+
$childbr->getTag()->selfClosing();
242+
243+
$parent->addChild($childa);
244+
$parent->addChild($childbr);
245+
$childa->addChild(new TextNode('link'));
246+
247+
$this->assertEquals('<div class="all"><a href=\'http://google.com\' ui-view>link</a><br /></div>', $parent->outerHtml);
248+
}
249+
227250
public function testText()
228251
{
229252
$a = new Tag('a');

0 commit comments

Comments
 (0)