fixes #6715

Includes a unit test - I ran it as a JSP but am not sure how we run our test suite