Fix for HTML strings containing non-ASCII characters

As proposed by evg1985. Solves string truncation and/or crash issues with strings containing multibyte chararcters