Added code and unit test to protect against XSS attacks