Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 7 additions & 1 deletion src/ios/CDVWKWebViewFileXhr.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,13 @@ - (void) performNativeXHR:(NSDictionary<NSString *, id> *) 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];
Expand Down