@@ -15,7 +15,9 @@ var filterNames = [
1515 'yd' , 'yc' ,
1616 'yavd' , 'yavs' , 'yavu' ,
1717 'yu' , 'yuc' ,
18- 'yubl' , 'yufull'
18+ 'yubl' , 'yufull' ,
19+ 'yceu' , 'yced' , 'yces' ,
20+ 'yceuu' , 'yceud' , 'yceus'
1921] ;
2022
2123console . log ( 'Integration test with Handlebars v' + Handlebars . VERSION ) ;
@@ -54,12 +56,42 @@ describe("secure handlebars helpers: error tests", function() {
5456 // yubl will not be independently used
5557 // expect(filter.yubl()).to.eql('undefined');
5658
59+ expect ( filter . yceu ( ) ) . to . eql ( 'undefined' ) ;
60+ expect ( filter . yced ( ) ) . to . eql ( 'undefined' ) ;
61+ expect ( filter . yces ( ) ) . to . eql ( 'undefined' ) ;
62+ expect ( filter . yceuu ( ) ) . to . eql ( 'undefined' ) ;
63+ expect ( filter . yceud ( ) ) . to . eql ( 'undefined' ) ;
64+ expect ( filter . yceus ( ) ) . to . eql ( 'undefined' ) ;
5765
58- expect ( filter . y ( ) ) . to . eql ( 'undefined ' ) ;
66+ expect ( filter . y ( ) ) . to . eql ( '' ) ;
5967 } ) ;
6068
61- } ) ;
69+ it ( 'filters handling of null input' , function ( ) {
70+
71+ expect ( filter . yd ( null ) ) . to . eql ( 'null' ) ;
72+ expect ( filter . yc ( null ) ) . to . eql ( 'null' ) ;
73+
74+ expect ( filter . yavd ( null ) ) . to . eql ( 'null' ) ;
75+ expect ( filter . yavs ( null ) ) . to . eql ( 'null' ) ;
76+ expect ( filter . yavu ( null ) ) . to . eql ( 'null' ) ;
77+
78+ expect ( filter . yu ( null ) ) . to . eql ( 'null' ) ;
79+ expect ( filter . yuc ( null ) ) . to . eql ( 'null' ) ;
80+ expect ( filter . yufull ( null ) ) . to . eql ( 'null' ) ;
81+ // yubl will not be independently used
82+ // expect(filter.yubl()).to.eql('null');
83+
84+ expect ( filter . yceu ( null ) ) . to . eql ( 'null' ) ;
85+ expect ( filter . yced ( null ) ) . to . eql ( 'null' ) ;
86+ expect ( filter . yces ( null ) ) . to . eql ( 'null' ) ;
87+ expect ( filter . yceuu ( null ) ) . to . eql ( 'null' ) ;
88+ expect ( filter . yceud ( null ) ) . to . eql ( 'null' ) ;
89+ expect ( filter . yceus ( null ) ) . to . eql ( 'null' ) ;
6290
91+ expect ( filter . y ( null ) ) . to . eql ( '' ) ;
92+ } ) ;
93+
94+ } ) ;
6395
6496/* the functional test is tested against in the contextparse-filters */
6597describe ( "secure handlebars helpers: compilation tests" , function ( ) {
@@ -108,6 +140,47 @@ describe("secure handlebars helpers: compilation tests", function() {
108140 expect ( output ) . to . eql ( '<div id="divid"></div>' ) ;
109141 } ) ;
110142
143+
144+ it ( 'filter yceu test' , function ( ) {
145+ var html = '<div style="background: {{{yceu value}}}"></div>' ;
146+ var json = { value : "red" } ;
147+ var output = compilation_test ( html , json ) ;
148+ expect ( output ) . to . eql ( '<div style="background: red"></div>' ) ;
149+ } ) ;
150+ it ( 'filter yced test' , function ( ) {
151+ var html = '<div style="background: "{{{yced value}}}""></div>' ;
152+ var json = { value : "red" } ;
153+ var output = compilation_test ( html , json ) ;
154+ expect ( output ) . to . eql ( '<div style="background: "red""></div>' ) ;
155+ } ) ;
156+ it ( 'filter yces test' , function ( ) {
157+ var html = '<div style="background: \'{{{yces value}}}\'"></div>' ;
158+ var json = { value : "red" } ;
159+ var output = compilation_test ( html , json ) ;
160+ expect ( output ) . to . eql ( '<div style="background: \'red\'"></div>' ) ;
161+ } ) ;
162+
163+
164+ it ( 'filter yceuu test' , function ( ) {
165+ var html = '<div style="background: url({{{yceuu value}}})"></div>' ;
166+ var json = { value : "javascript:alert(1)" } ;
167+ var output = compilation_test ( html , json ) ;
168+ expect ( output ) . to . eql ( '<div style="background: url(##javascript:alert\\28 1\\29 )"></div>' ) ;
169+ } ) ;
170+ it ( 'filter yceud test' , function ( ) {
171+ var html = '<div style="background: url("{{{yceud value}}}")"></div>' ;
172+ var json = { value : "javascript:alert(1)" } ;
173+ var output = compilation_test ( html , json ) ;
174+ expect ( output ) . to . eql ( '<div style="background: url("##javascript:alert(1)")"></div>' ) ;
175+ } ) ;
176+ it ( 'filter yceus test' , function ( ) {
177+ var html = '<div style="background: url(\'{{{yceus value}}}\')"></div>' ;
178+ var json = { value : "javascript:alert(1)" } ;
179+ var output = compilation_test ( html , json ) ;
180+ expect ( output ) . to . eql ( '<div style="background: url(\'##javascript:alert(1)\')"></div>' ) ;
181+ } ) ;
182+
183+
111184 it ( 'chained filter - yubl yavd yufull test' , function ( ) {
112185 var html = '<a href="{{{yubl (yavd (yufull url))}}}">link</a>' ;
113186 var json = { url : "javascript :alert(0);" } ;
@@ -175,7 +248,7 @@ describe("secure handlebars helpers: compilation tests", function() {
175248 var html = '<script>{{{y script}}}</script>' ;
176249 var json = { script : "&<>'\"&<>'\"" } ;
177250 var output = compilation_test ( html , json ) ;
178- expect ( output ) . to . eql ( '<script>&<>' ;"&<>' ;"</script>' ) ;
251+ expect ( output ) . to . eql ( '<script>&<>' ;"&<>' ;"</script>' ) ;
179252 } ) ;
180253
181254
0 commit comments