oracle / cordova-plugin-wkwebview-file-xhr

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

NativeXHR: Invalid url scheme 'null' #79

Open signalpoint opened 3 years ago

signalpoint commented 3 years ago

Thank you for this plugin, it really saved the day with regards to cordova + ios + xhr + cookies!

I wanted to point out an issue I had with the plugin though. For example, I am making a POST to a URL like this:

https://example.com/?q=api/foo.json&api-key=abc123!_^-etc

With NativeXHRLogging set to full, this error was being thrown to the Console:

NativeXHR: Invalid url scheme 'null'

After some Googling, it seems that NSURL may need some encoding.

To get around this, I added a one line patch to performNativeXHR() in CDVWKWebViewFileXhr.m:

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // PATCH

NSURL *url = [NSURL URLWithString:urlString];

I'm guessing if I were to encode the URL's query string parameters beforehand, that would eliminate the error (and the need for the patch). However, I haven't had to use encodeURIComponent() on either the q or api-key query string parameters for any other client environment (e.g. cordova + android, web apps, older versions ios + cordova), so I wanted to document this situation for others that may experience it.

Thank you again, and I hope this is helpful.

manish2788 commented 3 years ago

@signalpoint We will have look into your use case and respond soon.

leroydev commented 3 years ago

I'm running into this problem as well, have you guys figured out a way to solve it by any chance? :) @signalpoint @manish2788

Edit: I overlooked the workaround in CDVWKWebViewFileXhr.m, this worked for me as well. :)

kevsturman commented 2 months ago

Interesting to note that I've had reports of this error effecting some users but couldn't recreate it using the same url on a up to date test device. Until we realised the users with the error were on iOS v16.2.

It does look like the NSURL class has had the parser updated in iOS v17, see https://developer.apple.com/documentation/foundation/nsurl#1663756

For apps linked on or after iOS 17 and aligned OS versions, NSURL parsing has updated from the obsolete RFC 1738/1808 parsing to the same RFC 3986 parsing as NSURLComponents. This unifies the parsing behaviors of the NSURL and NSURLComponents APIs. Now, NSURL automatically percent- and IDNA-encodes invalid characters to help create a valid URL.