Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

WebView fails to load from urlwebviewsource with non-ascii characters (works with Uri) #1583

Closed
pfaucon opened this issue Jan 15, 2018 · 5 comments
Assignees
Projects

Comments

@pfaucon
Copy link

pfaucon commented Jan 15, 2018

Description

When loading a WebView with the 'Source' set as a Uri the webview is quite tolerant. If the 'Source' is setting using a UrlWebviewSource non-ascii characters cause the view to throw an exception

Steps to Reproduce

  1. create a page with a webview
  2. set the Source equal to a url with a non-ascii character

example :

<WebView x:Name="WebView" HorizontalOptions="FillAndExpand"
                     VerticalOptions="FillAndExpand">
 </WebView>
WebView.Source = new UrlWebViewSource { Url = "https://www.google.no/maps/place/Skøyen" };

Expected Behavior

it should escape the url as needed and load without exception. When setting the source with a new Uri object it behaves as expected.

Actual Behavior

Could not initialize an instance of the type 'Foundation.NSUrl': the native 'initWithString:' method returned nil.
It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.

Basic Information

Currently on Xamarin Forms
2.5.0.121934

@pauldipietro pauldipietro added this to New in Triage Jan 15, 2018
@StephaneDelcroix StephaneDelcroix moved this from New to Ready For Work in Triage Jan 16, 2018
@rmarinho rmarinho added this to Ready in v3.0.0 via automation Mar 15, 2018
@rmarinho rmarinho removed this from Ready For Work in Triage Mar 15, 2018
@rmarinho rmarinho moved this from Ready to In Review in v3.0.0 Mar 15, 2018
v3.0.0 automation moved this from In Review to Done Mar 19, 2018
@vladbilyk
Copy link

Hmmm, previous behavior (in Forms 2.x) was consistent: URL was not escaped on both platforms (iOS and Android), but now (Forms 3.0) on iOS provided URL is escaped, but on Android - not... It makes me crazy... I prefer the old one...

@capraynor
Copy link

capraynor commented May 25, 2018

The webview is not a browser, non-ascii character should escaped by user.
So I think this is not a bug, and should not fix that.
Suggest rollback entire pull request: #2111

@rmarinho
Copy link
Member

We are going to rever this fix, @pfaucon I think you will need to encode the url before sending it to forms

@pfaucon
Copy link
Author

pfaucon commented May 25, 2018

I think the inconsistency argument presented by @vladbilyk is a bit weak, it would not be more difficult to escape both iOS and Android.

@capraynor's argument is also weak/wrong. webview is rendererd on iOS using a UIWebView, I don't see a use case where an unescaped url has value, particularly when we know that on iOS it will error out, and the error provided is not very helpful. I'm not certain if Android will auto-escape the URL but it seems unlikely that escaping it will cause harm.

Is there a use case for having an unescaped url (or errors caused by escaping it)?

edit: the error provided is not completely useless, but it is not very helpful.

@pfaucon
Copy link
Author

pfaucon commented May 25, 2018

As a second counter to @vladbilyk's argument while XF doesn't escape the urls when loading on Android, someone does, as the page loads successfully in a new project using XF 2.5.0.121934 (but still fails in iOS as expected). I would then argue that fixing the bug in iOS in fact normalizes the platform more (instead of crash/work, it works on both platforms).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
v3.0.0
  
Done
Development

No branches or pull requests

5 participants