File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,7 +75,22 @@ function buildJavaOptions(options: http.HttpRequestOptions) {
7575
7676 var javaOptions = new com . tns . Async . Http . RequestOptions ( ) ;
7777
78- javaOptions . url = options . url . replace ( "%" , "%25" ) ;
78+ //HACK to fix the encoding https://github.com/NativeScript/NativeScript/pull/1228
79+ var originalUrl = options . url ;
80+ try {
81+ var decodedUrl = decodeURI ( originalUrl ) ;
82+ if ( decodedUrl === originalUrl ) {
83+ //the url is not encoded, fix the %
84+ options . url . replace ( "%" , "%25" ) ;
85+ }
86+ }
87+ catch ( e ) {
88+ //This means something crash with js decode encode (url malformed)
89+ // if we don't catch it will be and infinite loop, revert changes
90+ options . url = originalUrl ;
91+ }
92+ javaOptions . url = options . url ;
93+ //End of the HACK
7994
8095 if ( types . isString ( options . method ) ) {
8196 javaOptions . method = options . method ;
Original file line number Diff line number Diff line change @@ -19,8 +19,25 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
1919 var session = NSURLSession . sessionWithConfigurationDelegateDelegateQueue (
2020 sessionConfig , null , queue ) ;
2121
22+ //HACK to fix the encoding https://github.com/NativeScript/NativeScript/pull/1228
2223 var urlRequest = NSMutableURLRequest . requestWithURL (
23- NSURL . URLWithString ( options . url . replace ( "%" , "%25" ) ) ) ;
24+ - NSURL . URLWithString ( options . url ) ) ;
25+ var originalUrl = options . url ;
26+ try {
27+ var decodedUrl = decodeURI ( originalUrl ) ;
28+ if ( decodedUrl === originalUrl ) {
29+ //the url is not encoded, fix the %
30+ urlRequest = NSMutableURLRequest . requestWithURL (
31+ NSURL . URLWithString ( options . url . replace ( "%" , "%25" ) ) ) ;
32+ }
33+ }
34+ catch ( e ) {
35+ //This means something crash with js decode encode (url malformed)
36+ // if we don't catch it will be and infinite loop, revert changes
37+ urlRequest = NSMutableURLRequest . requestWithURL (
38+ - NSURL . URLWithString ( options . url ) ) ;
39+ }
40+ //End of the HACK
2441
2542 urlRequest . HTTPMethod = types . isDefined ( options . method ) ? options . method : GET ;
2643
You can’t perform that action at this time.
0 commit comments