diff --git a/CHANGELOG.md b/CHANGELOG.md
index beb5ec6f..3fbf0bb4 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,8 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## 3.1.1
+
+### Changed
+- Fixed issue with numbers in comments.
+- Updated minimume php version to correct version.
+- Comment tags are now self-closing when cleanup input is set to false.
+
## 3.1.0
+### Changed
- Updated to include Tidelift subscription option.
- Removed php-coverall.
- Removed Guzzle 6 Adapter.
diff --git a/README.md b/README.md
index c89f3bdf..6889b079 100755
--- a/README.md
+++ b/README.md
@@ -1,8 +1,6 @@
PHP Html Parser
==========================
-Version 3.1.0
-
[![Build Status](https://travis-ci.org/paquettg/php-html-parser.png)](https://travis-ci.org/paquettg/php-html-parser)
[![Coverage Status](https://coveralls.io/repos/paquettg/php-html-parser/badge.png)](https://coveralls.io/r/paquettg/php-html-parser)
[![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);
echo $dom; // '
');
```
-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.
+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.
```php
use PHPHtmlParser\Dom;
diff --git a/composer.json b/composer.json
index f8ca8450..166886f7 100755
--- a/composer.json
+++ b/composer.json
@@ -13,7 +13,7 @@
}
],
"require": {
- "php": ">=7.1",
+ "php": ">=7.2",
"ext-mbstring": "*",
"ext-zlib": "*",
"ext-curl": "*",
diff --git a/src/PHPHtmlParser/Content.php b/src/PHPHtmlParser/Content.php
index 888a6039..f1332175 100755
--- a/src/PHPHtmlParser/Content.php
+++ b/src/PHPHtmlParser/Content.php
@@ -72,6 +72,22 @@ public function char(?int $char = null): string
return $this->content[$char ?? $this->pos] ?? '';
}
+ /**
+ * Gets a string from the current character position.
+ *
+ * @param int $length
+ * @return string
+ */
+ public function string(int $length = 1): string
+ {
+ $string = '';
+ $position = $this->pos;
+ do {
+ $string .= $this->char($position++);
+ } while ($position < $this->pos + $length);
+ return $string;
+ }
+
/**
* Moves the current position forward.
*
diff --git a/src/PHPHtmlParser/Dom/Parser.php b/src/PHPHtmlParser/Dom/Parser.php
index 418e535c..7ed310cb 100644
--- a/src/PHPHtmlParser/Dom/Parser.php
+++ b/src/PHPHtmlParser/Dom/Parser.php
@@ -183,6 +183,14 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO
->setOpening('')
->setClosing(' ?>')
->selfClosing();
+ } elseif($content->string(3) == '!--') {
+ // comment tag
+ $tag = $content->fastForward(3)
+ ->copyByToken(StringToken::CLOSECOMMENT(), true);
+ $tag = (new Tag($tag))
+ ->setOpening('')
+ ->selfClosing();
} else {
$tag = \strtolower($content->copyByToken(StringToken::SLASH(), true));
if (\trim($tag) == '') {
diff --git a/src/PHPHtmlParser/Dom/Tag.php b/src/PHPHtmlParser/Dom/Tag.php
index 29b68bf7..2aeb6aa8 100644
--- a/src/PHPHtmlParser/Dom/Tag.php
+++ b/src/PHPHtmlParser/Dom/Tag.php
@@ -329,6 +329,8 @@ public function makeOpeningTag()
} catch (AttributeNotFoundException $e) {
// attribute that was in the array not found in the array... let's continue.
continue;
+ } catch (\TypeError $e) {
+ $val = null;
}
$val = $attributeDTO->getValue();
if (\is_null($val)) {
diff --git a/src/PHPHtmlParser/Enum/StringToken.php b/src/PHPHtmlParser/Enum/StringToken.php
index 6b60d520..7a209e00 100644
--- a/src/PHPHtmlParser/Enum/StringToken.php
+++ b/src/PHPHtmlParser/Enum/StringToken.php
@@ -11,6 +11,7 @@
* @method static StringToken EQUAL()
* @method static StringToken SLASH()
* @method static StringToken ATTR()
+ * @method static StringToken CLOSECOMMENT()
*/
class StringToken extends Enum
{
@@ -18,4 +19,5 @@ class StringToken extends Enum
private const EQUAL = ' =/>';
private const SLASH = " />\r\n\t";
private const ATTR = ' >';
+ private const CLOSECOMMENT = '-->';
}
diff --git a/tests/Dom/CommentTest.php b/tests/Dom/CommentTest.php
new file mode 100644
index 00000000..3f10696e
--- /dev/null
+++ b/tests/Dom/CommentTest.php
@@ -0,0 +1,34 @@
+setCleanupInput(false);
+ $dom->loadStr('', $options);
+ $this->dom = $dom;
+ }
+
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testLoadCommentInnerHtml()
+ {
+ $this->assertEquals('', $this->dom->innerHtml);
+ }
+}
diff --git a/tests/Node/TextTest.php b/tests/Node/TextTest.php
index 44298fc9..f94c4962 100755
--- a/tests/Node/TextTest.php
+++ b/tests/Node/TextTest.php
@@ -4,6 +4,7 @@
use PHPHtmlParser\Dom;
use PHPHtmlParser\Dom\Node\TextNode;
+use PHPHtmlParser\Options;
use PHPUnit\Framework\TestCase;
use stringEncode\Encode;