diff --git a/README.md b/README.md index 6b95c8b..8732731 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ -# cordova-plugin-wkwebview-file-xhr 3.1.0 +# NOTICE FOR DEVELOPERS USING WKWebView AND MapBox GL JS + +This fork fixes the issue that URLs are not correctly escaped. This is specifically an issue for programmers using WKWebView and MapBox GL JS in their Cordova apps. + +If you are receiving the error "ERROR: {message: "Bad request"}" after switching to WKWebView, then this is the fix for you! + +Unfortunately, Oracle (who developed this plugin originally) aren't accepting pull requests, so a fork is the only option. + +See: https://github.com/oracle/cordova-plugin-wkwebview-file-xhr/issues/53 + +# cordova-plugin-wkwebview-file-xhr 2.1.4 ## About the cordova-plugin-wkwebview-file-xhr diff --git a/src/ios/CDVWKWebViewFileXhr.m b/src/ios/CDVWKWebViewFileXhr.m index 18884ac..dc6a442 100644 --- a/src/ios/CDVWKWebViewFileXhr.m +++ b/src/ios/CDVWKWebViewFileXhr.m @@ -336,7 +336,13 @@ - (void) performNativeXHR:(NSDictionary *) body inWebView:(WKWeb return sendResult( @{ @"error" : @"Invalid url"}); } - NSURL *url = [NSURL URLWithString:urlString]; + NSURL *url; + if ([urlString rangeOfString:@"%"].location == NSNotFound) { + url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + } else { + urlString = [urlString stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; // BUGFIX: Meteoblue encodes everything except spaces! + url = [NSURL URLWithString:urlString]; + } if (![url.scheme.lowercaseString isEqualToString:@"http"] && ![url.scheme.lowercaseString isEqualToString:@"https"]) { NSString *msg = [NSString stringWithFormat:@"NativeXHR: Invalid url scheme '%@'; only http and https are supported by NativeXHR", url.scheme];