Correctly select IDs in BuildSelection.

By moving HTML quoting after selected matching.

Fixes bug#9631 - http://bugs.otrs.org/show_bug.cgi?id=9631
BuildSelection() Selected does not work if value contains strings
that are HTML-escaped.

Added unit test.