Bug 837748 - Refined the escapeHTML function and added unit testing

https://bugzilla.mozilla.org/show_bug.cgi?id=837748