Fix handling of invalid closing tags in HTML messages (#1489446)