Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing '>' in element content #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/TinyHtmlMinifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
$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)) {
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<script>
console.log('Script tags are not minified');
console.log('This is inside a script tag');
// Test greater than sign not stripped from scripts
if (1 > 2) {
console.log('This should not happen!');
}
</script>

</body>
Expand Down