oracle / cordova-plugin-wkwebview-file-xhr

Cordova Plugin for WebView File XHR
Universal Permissive License v1.0
138 stars 120 forks source link

URLs are not properly escaped! #53

Closed Pigsnuck closed 4 years ago

Pigsnuck commented 4 years ago

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.

Pigsnuck commented 4 years ago

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

manish2788 commented 4 years ago

Thanks @Pigsnuck. We will get back to you upon this with the fix

manish2788 commented 4 years ago

@Pigsnuck Can you provide a sample app demonstrating the issue you faced.

manish2788 commented 4 years ago

Closing this issue due to lack of response.