Skip to content

Commit 4e01a43

Browse files
authored
Merge pull request paquettg#251 from paquettg/dev/3.1.1
Dev/3.1.1
2 parents f5c2dd9 + 7c05e41 commit 4e01a43

File tree

9 files changed

+73
-4
lines changed

9 files changed

+73
-4
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 3.1.1
9+
10+
### Changed
11+
- Fixed issue with numbers in comments.
12+
- Updated minimume php version to correct version.
13+
- Comment tags are now self-closing when cleanup input is set to false.
14+
815
## 3.1.0
916

17+
### Changed
1018
- Updated to include Tidelift subscription option.
1119
- Removed php-coverall.
1220
- Removed Guzzle 6 Adapter.

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
PHP Html Parser
22
==========================
33

4-
Version 3.1.0
5-
64
[![Build Status](https://travis-ci.org/paquettg/php-html-parser.png)](https://travis-ci.org/paquettg/php-html-parser)
75
[![Coverage Status](https://coveralls.io/repos/paquettg/php-html-parser/badge.png)](https://coveralls.io/r/paquettg/php-html-parser)
86
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/paquettg/php-html-parser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/paquettg/php-html-parser/?branch=master)
@@ -258,7 +256,7 @@ unset($a);
258256
echo $dom; // '<div class="all"><p>Hey bro, <br /> :)</p></div>');
259257
```
260258

261-
You can modify the text of `TextNode` objects easely. Please note that, if you set an encoding, the new text will be encoded using the existing encoding.
259+
You can modify the text of `TextNode` objects easily. Please note that, if you set an encoding, the new text will be encoded using the existing encoding.
262260

263261
```php
264262
use PHPHtmlParser\Dom;

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.1",
16+
"php": ">=7.2",
1717
"ext-mbstring": "*",
1818
"ext-zlib": "*",
1919
"ext-curl": "*",

src/PHPHtmlParser/Content.php

+16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ public function char(?int $char = null): string
7272
return $this->content[$char ?? $this->pos] ?? '';
7373
}
7474

75+
/**
76+
* Gets a string from the current character position.
77+
*
78+
* @param int $length
79+
* @return string
80+
*/
81+
public function string(int $length = 1): string
82+
{
83+
$string = '';
84+
$position = $this->pos;
85+
do {
86+
$string .= $this->char($position++);
87+
} while ($position < $this->pos + $length);
88+
return $string;
89+
}
90+
7591
/**
7692
* Moves the current position forward.
7793
*

src/PHPHtmlParser/Dom/Parser.php

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO
183183
->setOpening('<?')
184184
->setClosing(' ?>')
185185
->selfClosing();
186+
} elseif($content->string(3) == '!--') {
187+
// comment tag
188+
$tag = $content->fastForward(3)
189+
->copyByToken(StringToken::CLOSECOMMENT(), true);
190+
$tag = (new Tag($tag))
191+
->setOpening('<!--')
192+
->setClosing('-->')
193+
->selfClosing();
186194
} else {
187195
$tag = \strtolower($content->copyByToken(StringToken::SLASH(), true));
188196
if (\trim($tag) == '') {

src/PHPHtmlParser/Dom/Tag.php

+2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ public function makeOpeningTag()
329329
} catch (AttributeNotFoundException $e) {
330330
// attribute that was in the array not found in the array... let's continue.
331331
continue;
332+
} catch (\TypeError $e) {
333+
$val = null;
332334
}
333335
$val = $attributeDTO->getValue();
334336
if (\is_null($val)) {

src/PHPHtmlParser/Enum/StringToken.php

+2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
* @method static StringToken EQUAL()
1212
* @method static StringToken SLASH()
1313
* @method static StringToken ATTR()
14+
* @method static StringToken CLOSECOMMENT()
1415
*/
1516
class StringToken extends Enum
1617
{
1718
private const BLANK = " \t\r\n";
1819
private const EQUAL = ' =/>';
1920
private const SLASH = " />\r\n\t";
2021
private const ATTR = ' >';
22+
private const CLOSECOMMENT = '-->';
2123
}

tests/Dom/CommentTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PHPHtmlParser\Dom;
6+
use PHPHtmlParser\Options;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class CommentTest extends TestCase
10+
{
11+
/**
12+
* @var Dom
13+
*/
14+
private $dom;
15+
16+
public function setUp()
17+
{
18+
$dom = new Dom();
19+
$options = new Options();
20+
$options->setCleanupInput(false);
21+
$dom->loadStr('<!-- test comment with number 2 -->', $options);
22+
$this->dom = $dom;
23+
}
24+
25+
public function tearDown()
26+
{
27+
Mockery::close();
28+
}
29+
30+
public function testLoadCommentInnerHtml()
31+
{
32+
$this->assertEquals('<!-- test comment with number 2 -->', $this->dom->innerHtml);
33+
}
34+
}

tests/Node/TextTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPHtmlParser\Dom;
66
use PHPHtmlParser\Dom\Node\TextNode;
7+
use PHPHtmlParser\Options;
78
use PHPUnit\Framework\TestCase;
89
use stringEncode\Encode;
910

0 commit comments

Comments
 (0)