@@ -56,35 +56,36 @@ export function disableSSLPinning() {
5656 policies . secured = false ;
5757}
5858
59- function nativeToObj ( data ) {
59+ function nativeToObj ( data , encoding ? ) {
6060 let content : any ;
6161 if ( data instanceof NSDictionary ) {
6262 content = { } ;
6363 data . enumerateKeysAndObjectsUsingBlock ( ( key , value , stop ) => {
64- content [ key ] = nativeToObj ( value ) ;
64+ content [ key ] = nativeToObj ( value , encoding ) ;
6565 } ) ;
6666 return content ;
6767 } else if ( data instanceof NSArray ) {
6868 content = [ ] ;
6969 data . enumerateObjectsUsingBlock ( ( value , index , stop ) => {
70- content [ index ] = nativeToObj ( value ) ;
70+ content [ index ] = nativeToObj ( value , encoding ) ;
7171 } ) ;
7272 return content ;
7373 } else if ( data instanceof NSData ) {
74- return NSString . alloc ( ) . initWithDataEncoding ( data , NSASCIIStringEncoding ) . toString ( ) ;
74+ return NSString . alloc ( ) . initWithDataEncoding ( data , encoding === 'ascii' ? NSASCIIStringEncoding : NSUTF8StringEncoding ) . toString ( ) ;
7575 } else {
7676 return data ;
7777 }
7878}
7979
80- function getData ( data ) {
80+ function getData ( data , encoding ? ) {
8181 let content : any ;
8282 if ( data && data . class ) {
83+ const nEncoding = encoding === 'ascii' ? NSASCIIStringEncoding : NSUTF8StringEncoding ;
8384 if ( data . enumerateKeysAndObjectsUsingBlock || data instanceof NSArray ) {
8485 const serial = NSJSONSerialization . dataWithJSONObjectOptionsError ( data , NSJSONWritingOptions . PrettyPrinted ) ;
85- content = NSString . alloc ( ) . initWithDataEncoding ( serial , NSUTF8StringEncoding ) . toString ( ) ;
86+ content = NSString . alloc ( ) . initWithDataEncoding ( serial , nEncoding ) . toString ( ) ;
8687 } else if ( data instanceof NSData ) {
87- content = NSString . alloc ( ) . initWithDataEncoding ( data , NSASCIIStringEncoding ) . toString ( ) ;
88+ content = NSString . alloc ( ) . initWithDataEncoding ( data , nEncoding ) . toString ( ) ;
8889 } else {
8990 content = data ;
9091 }
@@ -146,7 +147,7 @@ class HttpsResponseLegacy implements IHttpsResponseLegacy {
146147 this . stringResponse = this . data ;
147148 return this . data ;
148149 } else {
149- const data = nativeToObj ( this . data ) ;
150+ const data = nativeToObj ( this . data , encoding ) ;
150151 if ( typeof data === 'string' ) {
151152 this . stringResponse = data ;
152153 } else {
@@ -171,7 +172,7 @@ class HttpsResponseLegacy implements IHttpsResponseLegacy {
171172 this . jsonResponse = parseJSON ( this . stringResponse ) ;
172173 return this . jsonResponse ;
173174 }
174- const data = nativeToObj ( this . data ) ;
175+ const data = nativeToObj ( this . data , encoding ) ;
175176 if ( typeof data === 'object' ) {
176177 this . jsonResponse = data ;
177178 return data ;
0 commit comments