File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
src/internal/observable/dom Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -652,6 +652,39 @@ describe('Observable.ajax', () => {
652
652
expect ( complete ) . to . be . true ;
653
653
} ) ;
654
654
655
+ it ( 'should properly encode full URLs passed' , ( ) => {
656
+ const expected = { test : 'https://google.com/search?q=encodeURI+vs+encodeURIComponent' } ;
657
+ let result : Rx . AjaxResponse ;
658
+ let complete = false ;
659
+
660
+ Rx . Observable
661
+ . ajax . post ( '/flibbertyJibbet' , expected )
662
+ . subscribe ( x => {
663
+ result = x ;
664
+ } , null , ( ) => {
665
+ complete = true ;
666
+ } ) ;
667
+
668
+ const request = MockXMLHttpRequest . mostRecent ;
669
+
670
+ expect ( request . method ) . to . equal ( 'POST' ) ;
671
+ expect ( request . url ) . to . equal ( '/flibbertyJibbet' ) ;
672
+ expect ( request . requestHeaders ) . to . deep . equal ( {
673
+ 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
674
+ } ) ;
675
+
676
+ request . respondWith ( {
677
+ 'status' : 200 ,
678
+ 'contentType' : 'application/json' ,
679
+ 'responseText' : JSON . stringify ( expected )
680
+ } ) ;
681
+
682
+ expect ( request . data )
683
+ . to . equal ( 'test=https%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3DencodeURI%2Bvs%2BencodeURIComponent' ) ;
684
+ expect ( result . response ) . to . deep . equal ( expected ) ;
685
+ expect ( complete ) . to . be . true ;
686
+ } ) ;
687
+
655
688
it ( 'should succeed on 204 No Content' , ( ) => {
656
689
const expected = null ;
657
690
let result : Rx . AjaxResponse ;
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {
292
292
293
293
switch ( contentType ) {
294
294
case 'application/x-www-form-urlencoded' :
295
- return Object . keys ( body ) . map ( key => `${ encodeURI ( key ) } =${ encodeURI ( body [ key ] ) } ` ) . join ( '&' ) ;
295
+ return Object . keys ( body ) . map ( key => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( body [ key ] ) } ` ) . join ( '&' ) ;
296
296
case 'application/json' :
297
297
return JSON . stringify ( body ) ;
298
298
default :
You can’t perform that action at this time.
0 commit comments