From 9851d9875721109d0f5ee07f389f673500670a16 Mon Sep 17 00:00:00 2001
From: RajaTaimur7 <72160749+RajaTaimur7@users.noreply.github.com>
Date: Sat, 3 Oct 2020 00:23:08 +0500
Subject: [PATCH 1/6] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c89f3bdf..2d30b978 100755
--- a/README.md
+++ b/README.md
@@ -258,7 +258,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;
From 5572180311dc69ba195e7e6945570a73395ef9c9 Mon Sep 17 00:00:00 2001
From: Leon Kessler
Date: Mon, 26 Oct 2020 15:55:22 +0000
Subject: [PATCH 2/6] Fixes #247 numbers in comments can cause php fatal
errors.
---
src/PHPHtmlParser/Dom/Tag.php | 2 ++
tests/Node/TextTest.php | 11 +++++++++++
2 files changed, 13 insertions(+)
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/tests/Node/TextTest.php b/tests/Node/TextTest.php
index 44298fc9..ce7f0f59 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;
@@ -74,4 +75,14 @@ public function testSetTextEncoded()
$node->setText('biz baz');
$this->assertEquals('biz baz', $node->text());
}
+
+ public function testCommentWithNumbers() {
+ $dom = new Dom;
+ $options = new Options();
+ $options->setCleanupInput(false);
+ $dom->setOptions($options);
+ $dom->loadStr('');
+ $output = $dom->outerHtml;
+ $this->assertContains('', $output);
+ }
}
From 81341e1cfb9ce843ce50bd9b3715733ec5e5abfb Mon Sep 17 00:00:00 2001
From: Gilles Paquette
Date: Sun, 1 Nov 2020 19:45:49 +0000
Subject: [PATCH 3/6] Updated change log to reflect fix
---
CHANGELOG.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index beb5ec6f..eafc6357 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,8 +5,14 @@ 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
+
## 3.1.0
+### Changed
- Updated to include Tidelift subscription option.
- Removed php-coverall.
- Removed Guzzle 6 Adapter.
From ec1bc10b6acfa69cff1a7259a5abd051ad7f42d4 Mon Sep 17 00:00:00 2001
From: Gilles Paquette
Date: Sun, 1 Nov 2020 19:50:43 +0000
Subject: [PATCH 4/6] fixed #246 Fixed php version dependency.
---
CHANGELOG.md | 3 ++-
composer.json | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eafc6357..065e5b36 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## 3.1.1
### Changed
-- Fixed issue with numbers in comments
+- Fixed issue with numbers in comments.
+- Updated minimume php version to correct version.
## 3.1.0
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": "*",
From 40c335b512969bbfeb819771eabd130a40170338 Mon Sep 17 00:00:00 2001
From: Gilles Paquette
Date: Sun, 1 Nov 2020 20:15:40 +0000
Subject: [PATCH 5/6] fix #233 - Made comments self-closing
---
CHANGELOG.md | 1 +
src/PHPHtmlParser/Content.php | 16 ++++++++++++
src/PHPHtmlParser/Dom/Parser.php | 8 ++++++
src/PHPHtmlParser/Enum/StringToken.php | 2 ++
tests/Dom/CommentTest.php | 34 ++++++++++++++++++++++++++
tests/Node/TextTest.php | 10 --------
6 files changed, 61 insertions(+), 10 deletions(-)
create mode 100644 tests/Dom/CommentTest.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 065e5b36..3fbf0bb4 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 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
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/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 ce7f0f59..f94c4962 100755
--- a/tests/Node/TextTest.php
+++ b/tests/Node/TextTest.php
@@ -75,14 +75,4 @@ public function testSetTextEncoded()
$node->setText('biz baz');
$this->assertEquals('biz baz', $node->text());
}
-
- public function testCommentWithNumbers() {
- $dom = new Dom;
- $options = new Options();
- $options->setCleanupInput(false);
- $dom->setOptions($options);
- $dom->loadStr('');
- $output = $dom->outerHtml;
- $this->assertContains('', $output);
- }
}
From 7c05e4192a918cb72902499d275a5b9fa7779d7e Mon Sep 17 00:00:00 2001
From: Gilles Paquette
Date: Sun, 1 Nov 2020 20:33:18 +0000
Subject: [PATCH 6/6] Removed version number from readme
---
README.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/README.md b/README.md
index 2d30b978..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)