URLs are not properly escaped!
Pigsnuck opened this issue · 4 comments
After quite a bit of digging, I found out why cordova-plugin-wkwebkit-file-xhr is not correctly loading Mapbox GL JS URLs, even when the following preference is set in config.xml.
<preference name="InterceptRemoteRequests" value="all" />
The following error is displayed any time I want to get a MapBox URL:
ERROR: {"message":"Bad Request"}
The reason is simple (but hard to find!): URLs are not being correctly escaped!
The fix is even simpler.
Replace line 339 in platforms/iOS/[Project Name]/Plugins/CDVWKWebViewFileXhr.m
from this:
NSURL *url = [NSURL URLWithString:urlString];
To this:
NSURL *url;
if ([urlString rangeOfString:@"%"].location == NSNotFound) {
url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
} else {
url = [NSURL URLWithString:urlString];
}
I haven't bothered to create a pull request, as Oracle have stated they will not accept them. You will have to apply this patch manually.
Update: I created a fork with my fix. You can use that in your Cordova project if you prefer.
See: https://github.com/Pigsnuck/cordova-plugin-wkwebview-file-xhr
Thanks @Pigsnuck. We will get back to you upon this with the fix
@Pigsnuck Can you provide a sample app demonstrating the issue you faced.
Closing this issue due to lack of response.