Search.Filter.Charset: Improve robustness against encoding errors.

Some character encodings (lie eg UTF-8) contain illegal sequences,
make sure that the caller doesn't die if the data has invalid markup.

Fixes [bug 6175].