@@ -144,11 +144,17 @@ describe('security options', function() {
144144
145145 it ( 'can make a real local data uri request when selfRequestOnly false' , function ( done ) {
146146 htmx . config . selfRequestsOnly = false
147+ var pathVerifier = htmx . on ( 'htmx:validateUrl' , function ( evt ) {
148+ if ( evt . detail . sameHost === false && evt . detail . url . protocol !== 'data:' ) {
149+ evt . preventDefault ( )
150+ }
151+ } )
147152 this . server . restore ( ) // use real xhrs
148153 var btn = make ( '<button hx-get="data:,foo">Initial</button>' )
149154 btn . click ( )
150155 htmx . config . selfRequestsOnly = true
151156 setTimeout ( function ( ) {
157+ htmx . off ( 'htmx:validateUrl' , pathVerifier )
152158 btn . innerHTML . should . equal ( 'foo' )
153159 done ( )
154160 } , 30 )
@@ -211,38 +217,66 @@ describe('security options', function() {
211217
212218 it ( 'can cancel egress request based on htmx:validateUrl event' , function ( done ) {
213219 this . timeout ( 4000 )
220+ htmx . config . selfRequestsOnly = false
214221 // should trigger send error, rather than reject
215222 var pathVerifier = htmx . on ( 'htmx:validateUrl' , function ( evt ) {
216223 evt . preventDefault ( )
217- htmx . off ( 'htmx:validateUrl' , pathVerifier )
218224 } )
219225 var listener = htmx . on ( 'htmx:invalidPath' , function ( ) {
220226 htmx . off ( 'htmx:invalidPath' , listener )
227+ htmx . off ( 'htmx:validateUrl' , pathVerifier )
221228 done ( )
222229 } )
223230 this . server . restore ( ) // use real xhrs
224231 // will 404, but should respond
225232 var btn = make ( '<button hx-get="https://hypermedia.systems/www/test">Initial</button>' )
226233 btn . click ( )
234+ htmx . config . selfRequestsOnly = true
227235 } )
228236
229237 it ( 'can cancel egress request based on htmx:validateUrl event, sameHost is false' , function ( done ) {
230238 this . timeout ( 4000 )
239+ htmx . config . selfRequestsOnly = false
231240 // should trigger send error, rather than reject
232241 var pathVerifier = htmx . on ( 'htmx:validateUrl' , function ( evt ) {
233242 if ( evt . detail . sameHost === false ) {
234243 evt . preventDefault ( )
235244 }
236- htmx . off ( 'htmx:validateUrl' , pathVerifier )
237245 } )
238246 var listener = htmx . on ( 'htmx:invalidPath' , function ( ) {
247+ htmx . off ( 'htmx:validateUrl' , pathVerifier )
239248 htmx . off ( 'htmx:invalidPath' , listener )
240249 done ( )
241250 } )
242251 this . server . restore ( ) // use real xhrs
243252 // will 404, but should respond
244253 var btn = make ( '<button hx-get="https://hypermedia.systems/www/test">Initial</button>' )
245254 btn . click ( )
255+ htmx . config . selfRequestsOnly = true
256+ } )
257+
258+ it ( 'can cancel egress request based on htmx:validateUrl event and then allow a request' , function ( done ) {
259+ htmx . config . selfRequestsOnly = false
260+ var requestCount = 0
261+ var pathVerifier = htmx . on ( 'htmx:validateUrl' , function ( evt ) {
262+ requestCount = requestCount + 1
263+ if ( requestCount === 1 ) {
264+ evt . preventDefault ( )
265+ }
266+ } )
267+ this . server . restore ( ) // use real xhrs
268+ var btn = make ( '<button hx-get="data:,foo">Initial</button>' )
269+ btn . click ( )
270+ setTimeout ( function ( ) {
271+ btn . innerHTML . should . not . equal ( 'foo' )
272+ btn . click ( )
273+ setTimeout ( function ( ) {
274+ htmx . off ( 'htmx:validateUrl' , pathVerifier )
275+ htmx . config . selfRequestsOnly = true
276+ btn . innerHTML . should . equal ( 'foo' )
277+ done ( )
278+ } , 30 )
279+ } , 30 )
246280 } )
247281
248282 it ( 'can disable script tag support with htmx.config.allowScriptTags' , function ( ) {
0 commit comments