@@ -220,6 +220,22 @@ define(['jquery'], function ($) {define('select2/utils',[
220220 $el . innerWidth ( ) < el . scrollWidth ) ;
221221 } ;
222222
223+ Utils . escapeMarkup = function ( markup ) {
224+ var replaceMap = {
225+ '\\' : '\' ,
226+ '&' : '&' ,
227+ '<' : '<' ,
228+ '>' : '>' ,
229+ '"' : '"' ,
230+ '\'' : ''' ,
231+ '/' : '/'
232+ } ;
233+
234+ return String ( markup ) . replace ( / [ & < > " ' \/ \\ ] / g, function ( match ) {
235+ return replaceMap [ match ] ;
236+ } ) ;
237+ } ;
238+
223239 return Utils ;
224240} ) ;
225241
@@ -698,13 +714,14 @@ define('select2/results',[
698714
699715 Results . prototype . template = function ( result , container ) {
700716 var template = this . options . get ( 'templateResult' ) ;
717+ var escapeMarkup = this . options . get ( 'escapeMarkup' ) ;
701718
702719 var content = template ( result ) ;
703720
704721 if ( content == null ) {
705722 container . style . display = 'none' ;
706723 } else {
707- container . innerHTML = content ;
724+ container . innerHTML = escapeMarkup ( content ) ;
708725 }
709726 } ;
710727
@@ -942,8 +959,9 @@ define('select2/selection/single',[
942959
943960 SingleSelection . prototype . display = function ( data ) {
944961 var template = this . options . get ( 'templateSelection' ) ;
962+ var escapeMarkup = this . options . get ( 'escapeMarkup' ) ;
945963
946- return template ( data ) ;
964+ return escapeMarkup ( template ( data ) ) ;
947965 } ;
948966
949967 SingleSelection . prototype . selectionContainer = function ( ) {
@@ -1020,8 +1038,9 @@ define('select2/selection/multiple',[
10201038
10211039 MultipleSelection . prototype . display = function ( data ) {
10221040 var template = this . options . get ( 'templateSelection' ) ;
1041+ var escapeMarkup = this . options . get ( 'escapeMarkup' ) ;
10231042
1024- return template ( data ) ;
1043+ return escapeMarkup ( template ( data ) ) ;
10251044 } ;
10261045
10271046 MultipleSelection . prototype . selectionContainer = function ( ) {
@@ -3894,6 +3913,7 @@ define('select2/defaults',[
38943913 this . defaults = {
38953914 amdBase : 'select2/' ,
38963915 amdLanguageBase : 'select2/i18n/' ,
3916+ escapeMarkup : Utils . escapeMarkup ,
38973917 language : EnglishTranslation ,
38983918 matcher : matcher ,
38993919 minimumInputLength : 0 ,
0 commit comments