Add test for html_escape on non-strings

If escape_html is set, the argument passed to html_escape is not
necessarily a string (in the generated code it is passed before being
interpolated).

Add test to check html_escape converts non-strings.

See #673
(cherry picked from commit 4511a75288728577000bec69a667e269faf0c78c)
don't create new regex with fixes encoding each time html_escape is called
(cherry picked from commit 80f70235da6caf7b79bf8644db0c2685c145b4de)

Fixes #673
Fix html_escape failure with frozen strings

Closes #652
(cherry picked from commit 8241fb228bba0412b998e0d3af58634ba12a364e)