@@ -96,48 +96,67 @@ describe("documentjs/lib/generators/html",function(){
96
96
} ) ;
97
97
} ) ;
98
98
99
- it ( "closing script tags are properly escaped" , function ( done ) {
99
+ it ( "closing script tags are properly escaped" , function ( ) {
100
100
this . timeout ( 40000 ) ;
101
- rmdir ( path . join ( __dirname , "test" , "tmp" ) , function ( e ) {
102
- if ( e ) {
103
- return done ( e ) ;
104
- }
105
- var options = {
106
- dest : path . join ( __dirname , "test" , "tmp" ) ,
107
- parent : "index" ,
108
- templateRender : true
109
- } ;
110
-
111
-
112
- var docMap = Q . Promise ( function ( resolve ) {
113
- resolve ( _ . assign ( {
114
- index : {
115
- name : "index" ,
116
- type : "page" ,
117
- body : "Hello `{{thing.params.0.script}}`"
118
- } ,
119
- thing : {
120
- name : "thing" ,
121
- params : [
122
- { script : "<script>function() {return true; }</script>" }
123
- ]
124
- }
125
- } ) ) ;
126
- } ) ;
127
101
128
- html . generate ( docMap , options ) . then ( function ( ) {
129
- fs . readFile (
130
- path . join ( __dirname , "test" , "tmp" , "index.html" ) ,
131
- function ( err , data ) {
132
- if ( err ) {
133
- done ( err ) ;
102
+ return Q . denodeify ( rmdir ) ( path . join ( __dirname , "test" , "tmp" ) )
103
+ . then ( function ( ) {
104
+ var options = {
105
+ dest : path . join ( __dirname , "test" , "tmp" ) ,
106
+ parent : "index" ,
107
+ templateRender : true
108
+ } ;
109
+
110
+ var docMap = Q . Promise ( function ( resolve ) {
111
+ resolve ( _ . assign ( {
112
+ index : {
113
+ name : "index" ,
114
+ type : "page" ,
115
+ body : [
116
+ "Hello `{{thing.params.0.script}}`" ,
117
+ "Load steal using \n\n `{{thing.params.1.script}}`"
118
+ ] . join ( "\n" )
119
+ } ,
120
+ thing : {
121
+ name : "thing" ,
122
+ params : [
123
+ { script : "<script>function() {return true; }</script>" } ,
124
+ { script : "<script src=\"./dist/steal/steal.js\"></script>" }
125
+ ]
134
126
}
135
- assert . ok ( ( "" + data ) . includes ( "<code>&lt;script&gt;function() {return true; }&lt;\/script&gt;<\/code>" ) , "script closing tag escaped" ) ;
136
- done ( ) ;
137
- } ) ;
138
-
139
- } , done ) ;
140
- } ) ;
127
+ } ) ) ;
128
+ } ) ;
129
+
130
+ return html . generate ( docMap , options ) ;
131
+ } )
132
+ . then ( function ( ) {
133
+ return readFile ( path . join ( __dirname , "test" , "tmp" , "index.html" ) ) ;
134
+ } )
135
+ . then ( function ( data ) {
136
+ var index = data . toString ( ) ;
137
+
138
+ assert . ok (
139
+ index . includes ( "<code>&lt;script&gt;function() {return true; }&lt;\/script&gt;<\/code>" ) ,
140
+ "script closing tag escaped"
141
+ ) ;
142
+ } )
143
+ . then ( function ( ) {
144
+ return readFile ( path . join ( __dirname , "test" , "tmp" , "thing.html" ) ) ;
145
+ } )
146
+ . then ( function ( data ) {
147
+ var content = data . toString ( ) ;
148
+ var rx = / < \/ s c r i p t > / g;
149
+
150
+ var docObject = content . substring (
151
+ content . indexOf ( "var docObject = " ) ,
152
+ content . indexOf ( "};" , content . indexOf ( "var docObject = " ) )
153
+ ) ;
154
+
155
+ assert . ok (
156
+ ! rx . test ( docObject ) ,
157
+ "docObject should not have unscaped closing script tags"
158
+ ) ;
159
+ } ) ;
141
160
} ) ;
142
161
143
162
it ( "slashes get put in a folder and can link correctly" , function ( done ) {
0 commit comments