fields icon indicating copy to clipboard operation
fields copied to clipboard

URL with without https:// fails

Open nelsonic opened this issue 5 years ago • 3 comments

We are using Fields.url in a project and a user is attempting to insert a url:

www.example.com

To the user, this looks like a perfectly valid URL, sadly our regex in #16 rejects a url without a protocol.

Question:

Do we want to allow urls without a protocol (i.e. be user-friendly) or do we want to be strict and continue rejecting them?

nelsonic avatar May 15 '19 10:05 nelsonic

Relevant test: https://github.com/dwyl/fields/blob/a40df5c9856bbf21fdd31f16c724fc8a7201fa53/test/url_test.exs#L21

nelsonic avatar May 15 '19 11:05 nelsonic

Sadly only 56.6% of websites use HTTPS: https://w3techs.com/technologies/details/ce-httpsdefault image

However most of the top sites use HTTPS: https://transparencyreport.google.com/https/overview image

The last thing we want is a person being blocked from adding a link to the @dwyl app because it does not start with https:// ... so think we may need to update the regular expression to be more permissive.

nelsonic avatar Dec 01 '19 21:12 nelsonic

@nelsonic
Bumped into this. Maybe something like below if this is still relevant?


> Enum.any?([:scheme, :authority, :host], &Map.get(URI.parse(url), &1))

> u = URI.parse("www.test.com")
%URI{
  scheme: nil,
  userinfo: nil,
  host: nil,
  port: nil,
  path: "://www.test.com",
  query: nil,
  fragment: nil
}
> Enum.any?([:scheme, :authority, :host], &Map.get(u,&1))
false

##

>u = URI.parse("://www.test.com")
%URI{
  scheme: nil,
  userinfo: nil,
  host: nil,
  port: nil,
  path: "www.test.com",
  query: nil,
  fragment: nil
}
>Enum.any?([:scheme, :authority, :host], &Map.get(u,&1))
false

##
>u = URI.parse("ftp://www.test.com")
%URI{
  scheme: "ftp",
  authority: "www.test.com",
  userinfo: nil,
  host: "www.test.com",
  port: 21,
  path: nil,
  query: nil,
  fragment: nil
}
>Enum.any?([:scheme, :authority, :host], &Map.get(u,&1))
true

> u = URI.parse("https://www.test.com?p=1")
%URI{
  scheme: "https",
  authority: "www.test.com",
  userinfo: nil,
  host: "www.test.com",
  port: 443,
  path: nil,
  query: "p=1",
  fragment: nil
}
> Enum.any?([:scheme, :authority, :host], &Map.get(u,&1))
true

ndrean avatar Sep 23 '23 13:09 ndrean