File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -531,10 +531,13 @@ export class ComboboxView extends TextView {
531
531
this . isInitialRender = false ;
532
532
533
533
const opts = this . model . get ( 'options' ) as string [ ] ;
534
- const optLines = opts . map ( o => {
535
- return `<option value="${ o } "></option>` ;
536
- } ) ;
537
- this . datalist . innerHTML = optLines . join ( '\n' ) ;
534
+ const optionFragment = document . createDocumentFragment ( ) ;
535
+ for ( const v of opts ) {
536
+ const o = document . createElement ( 'option' ) ;
537
+ o . value = v ;
538
+ optionFragment . appendChild ( o ) ;
539
+ }
540
+ this . datalist . appendChild ( optionFragment ) ;
538
541
}
539
542
540
543
isValid ( value : string ) : boolean {
Original file line number Diff line number Diff line change @@ -66,4 +66,27 @@ describe('ComboboxView', function() {
66
66
view . textbox . classList . contains ( 'jpwidgets-invalidComboValue' )
67
67
) . to . equal ( true ) ;
68
68
} ) ;
69
+
70
+ it ( 'escapes characters in options' , function ( ) {
71
+ const input = [
72
+ 'foo"' ,
73
+ '"><script>alert("foo")</script><a "' ,
74
+ '" onmouseover=alert(1) "'
75
+ ] ;
76
+ this . model . set ( {
77
+ value : 'ABC' ,
78
+ options : input ,
79
+ ensure_option : true
80
+ } ) ;
81
+ const options = { model : this . model } ;
82
+ const view = new widgets . ComboboxView ( options ) ;
83
+ view . render ( ) ;
84
+ expect ( view . datalist ! . children . length ) . to . equal ( 3 ) ;
85
+ for ( let i = 0 ; i < view . datalist ! . children . length ; ++ i ) {
86
+ const el = view . datalist ! . children [ i ] ;
87
+ expect ( el . tagName . toLowerCase ( ) ) . to . equal ( 'option' ) ;
88
+ expect ( el . getAttributeNames ( ) ) . to . eqls ( [ 'value' ] ) ;
89
+ expect ( el . getAttribute ( 'value' ) ) . to . equal ( input [ i ] ) ;
90
+ }
91
+ } ) ;
69
92
} ) ;
You can’t perform that action at this time.
0 commit comments