File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -1802,10 +1802,10 @@ $.extend(Selectize.prototype, {
1802
1802
}
1803
1803
if ( templateName === 'optgroup' ) {
1804
1804
id = data [ self . settings . optgroupValueField ] || '' ;
1805
- html = html . replace ( regex_tag , '<$1 data-group="' + escape_html ( id ) + '"' ) ;
1805
+ html = html . replace ( regex_tag , '<$1 data-group="' + escape_replace ( escape_html ( id ) ) + '"' ) ;
1806
1806
}
1807
1807
if ( templateName === 'option' || templateName === 'item' ) {
1808
- html = html . replace ( regex_tag , '<$1 data-value="' + escape_html ( value || '' ) + '"' ) ;
1808
+ html = html . replace ( regex_tag , '<$1 data-value="' + escape_replace ( escape_html ( value || '' ) ) + '"' ) ;
1809
1809
}
1810
1810
1811
1811
// update cache
Original file line number Diff line number Diff line change @@ -44,6 +44,16 @@ var escape_html = function(str) {
44
44
. replace ( / " / g, '"' ) ;
45
45
} ;
46
46
47
+ /**
48
+ * Escapes "$" characters in replacement strings.
49
+ *
50
+ * @param {string } str
51
+ * @returns {string }
52
+ */
53
+ var escape_replace = function ( str ) {
54
+ return ( str + '' ) . replace ( / \$ / g, '$$$$' ) ;
55
+ } ;
56
+
47
57
var hook = { } ;
48
58
49
59
/**
Original file line number Diff line number Diff line change 195
195
{ value : 'a' } ,
196
196
{ value : 'b' } ,
197
197
{ value : 'c' } ,
198
+ { value : '$1' } ,
198
199
{ value : '\'' } ,
199
200
{ value : '"' } ,
200
201
{ value : '\\\'' } ,
231
232
it ( 'should update DOM' , function ( ) {
232
233
test . selectize . addItem ( 'c' ) ;
233
234
expect ( test . selectize . $control . find ( '[data-value=c]' ) . length ) . to . be . equal ( 1 ) ;
235
+
236
+ test . selectize . addItem ( '$1' ) ;
237
+ var found = false ;
238
+ test . selectize . $control . children ( ) . each ( function ( ) {
239
+ if ( this . getAttribute ( 'data-value' ) === '$1' ) {
240
+ found = true ;
241
+ return false ;
242
+ }
243
+ } ) ;
244
+ expect ( found ) . to . be . equal ( true ) ;
234
245
} ) ;
235
246
} ) ;
236
247
You can’t perform that action at this time.
0 commit comments