tiny-html-minifier icon indicating copy to clipboard operation
tiny-html-minifier copied to clipboard

Bug: Addition < at first line

Open sotatek-truongpham opened this issue 2 years ago • 1 comments

With text ■Campaign Overview update:
result: <■Campaign Overview update:

sotatek-truongpham avatar Apr 27 '22 10:04 sotatek-truongpham

So, after investigating, this happens when the $html we supply doesn't start with an element. To combat this, I have changed the html function in TinyMinify to this:

  public static function html(string $html, array $options = []) : string
   {
       $minifier = new TinyHtmlMinifier($options);
       $result = $minifier->minify($html);
       
       $min_char1 = substr($result,0,1);
       if ($min_char1 == substr($html,0,1)) {
	        return $result;
       } else {
	        if ($min_char1 == '<') {
		        return substr($result, 1);
	        }
       }
   }

Probably not the best way to combat it, but it works for my use case.

davidcmoody avatar Aug 02 '23 16:08 davidcmoody