Convert html input to string before processing

This sanitization step works around an issue with safe buffers in recent
versions of Rails. The bug breaks $* variables in the context of gsub
blocks, resulting in all entities being replaced with the empty string
(''). See https://github.com/rails/rails/issues/1555 for more details.