Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeXHR: Invalid url scheme 'null' #79

Open
signalpoint opened this issue Feb 5, 2021 · 3 comments
Open

NativeXHR: Invalid url scheme 'null' #79

signalpoint opened this issue Feb 5, 2021 · 3 comments

Comments

@signalpoint
Copy link

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
Copy link
Member

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

callum-spartan added a commit to spartansolutions/cordova-plugin-wkwebview-file-xhr that referenced this issue Jun 14, 2021
@leroydev
Copy link

leroydev commented Jul 5, 2021

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. :)

fauzy6493 pushed a commit to fauzy6493/cordova-plugin-wkwebview-file-xhr that referenced this issue Feb 23, 2024
@kevsturman
Copy link

kevsturman commented Jun 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants