From d89154a0783906a51e220da28944ea6f1c475e2d Mon Sep 17 00:00:00 2001 From: Craig Payne Date: Tue, 19 May 2020 15:23:22 +0200 Subject: [PATCH 1/4] BUGFIX: URLs are not correctly escaped. --- src/ios/CDVWKWebViewFileXhr.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVWKWebViewFileXhr.m b/src/ios/CDVWKWebViewFileXhr.m index 18884ac..337d081 100644 --- a/src/ios/CDVWKWebViewFileXhr.m +++ b/src/ios/CDVWKWebViewFileXhr.m @@ -336,7 +336,7 @@ - (void) performNativeXHR:(NSDictionary *) body inWebView:(WKWeb return sendResult( @{ @"error" : @"Invalid url"}); } - NSURL *url = [NSURL URLWithString:urlString]; + NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 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]; From bb220e88a860463cc428a2769bb73eb3ed1ea782 Mon Sep 17 00:00:00 2001 From: Pigsnuck Date: Tue, 19 May 2020 15:32:07 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index ee5257a..317018b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ +# 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 From 619542ed9aa6cd38732423da2a7f5fff71770963 Mon Sep 17 00:00:00 2001 From: Craig Payne Date: Tue, 19 May 2020 16:10:15 +0200 Subject: [PATCH 3/4] BUGFIX: URLs that are already escaped are escaped again. --- src/ios/CDVWKWebViewFileXhr.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ios/CDVWKWebViewFileXhr.m b/src/ios/CDVWKWebViewFileXhr.m index 337d081..ea13c0c 100644 --- a/src/ios/CDVWKWebViewFileXhr.m +++ b/src/ios/CDVWKWebViewFileXhr.m @@ -336,7 +336,12 @@ - (void) performNativeXHR:(NSDictionary *) body inWebView:(WKWeb return sendResult( @{ @"error" : @"Invalid url"}); } - NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + NSURL *url; + if ([urlString rangeOfString:@"%"].location == NSNotFound) { + url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + } else { + 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]; From d7c3346f4f264a8c73e9fa1eca87750e6247c580 Mon Sep 17 00:00:00 2001 From: Craig Payne Date: Tue, 9 Aug 2022 15:44:31 +0200 Subject: [PATCH 4/4] BUGFIX: Meteoblue encodes everything except spaces! This causes live wind animation to not work. --- src/ios/CDVWKWebViewFileXhr.m | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ios/CDVWKWebViewFileXhr.m b/src/ios/CDVWKWebViewFileXhr.m index ea13c0c..dc6a442 100644 --- a/src/ios/CDVWKWebViewFileXhr.m +++ b/src/ios/CDVWKWebViewFileXhr.m @@ -340,6 +340,7 @@ - (void) performNativeXHR:(NSDictionary *) body inWebView:(WKWeb 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]; }