ivaynberg/select2 — pull request #375 by hitsthings (2012-09-04 06:43:15+00:00)
Title: formatResult and formatSelection should escape

I have followed a number of issues revolving around escapeMarkup that seem to recur, and I
believe the solutions you are choosing are good, but don't get at the root cause of the problem.
I believe the root of the problem is that it is used in the wrong place.

If formatSelection and formatResult are expected to return HTML, then you should not be calling
any escaping function on their output. Instead, you should expect that the job of "formatting" is to convert text into HTML, which includes escaping.

This means that your impl of formatSelection and formatResult should call escapeMarkup, and that escapeMarkup needs to be robust enough to sanitize any string (it shouldn't expect pre-escaped text).

NOTE: This is not yet tested. Might not even run. I'll take a look in a bit, but unless you're expecting to do a new release really soon, my priority is to fix up the version I have now (3.1).