From a30e2953110ffed6b0d799dea42a7f30ee4c6efb Mon Sep 17 00:00:00 2001 From: Matthew Kilpatrick <16194494+Matthew-Kilpatrick@users.noreply.github.com> Date: Sat, 27 Feb 2021 18:50:22 +0000 Subject: [PATCH 1/2] Fix greater than sign parsing inside element content Fix contnet of element body being truncated after first occurrence of a greater than sign (>), which can cause issues in some circumstances, such as a conditional evaluation inside a script tag. Relates to issue #21 --- src/TinyHtmlMinifier.php | 2 +- tests/tests.html | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TinyHtmlMinifier.php b/src/TinyHtmlMinifier.php index d628c06..65f0841 100644 --- a/src/TinyHtmlMinifier.php +++ b/src/TinyHtmlMinifier.php @@ -85,7 +85,7 @@ public function minify(string $html) : string // Walk trough html private function walk(&$part) { - $tag_parts = explode('>', $part); + $tag_parts = explode('>', $part, 2); // Limit of 2 parts to prevent issues with '>' in content (eg. JS comparison) $tag_content = $tag_parts[0]; if (!empty($tag_content)) { diff --git a/tests/tests.html b/tests/tests.html index 212464e..0e2354e 100644 --- a/tests/tests.html +++ b/tests/tests.html @@ -66,6 +66,10 @@ From c004782ee37bc7b65344958adc6e22314fad4a3d Mon Sep 17 00:00:00 2001 From: Matthew Kilpatrick <16194494+Matthew-Kilpatrick@users.noreply.github.com> Date: Sat, 27 Feb 2021 20:43:34 +0000 Subject: [PATCH 2/2] Fix typo & indentation --- src/TinyHtmlMinifier.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TinyHtmlMinifier.php b/src/TinyHtmlMinifier.php index 65f0841..8c914c7 100644 --- a/src/TinyHtmlMinifier.php +++ b/src/TinyHtmlMinifier.php @@ -82,10 +82,10 @@ public function minify(string $html) : string return $this->output; } - // Walk trough html + // Walk through html private function walk(&$part) { - $tag_parts = explode('>', $part, 2); // Limit of 2 parts to prevent issues with '>' in content (eg. JS comparison) + $tag_parts = explode('>', $part, 2); // Limit of 2 parts to prevent issues with '>' in content (eg. JS comparison) $tag_content = $tag_parts[0]; if (!empty($tag_content)) {