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

URL with without https:// fails #34

Open
nelsonic opened this issue May 15, 2019 · 3 comments
Open

URL with without https:// fails #34

nelsonic opened this issue May 15, 2019 · 3 comments
Labels
discuss help wanted Extra attention is needed question Further information is requested

Comments

@nelsonic
Copy link
Member

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 nelsonic added question Further information is requested discuss labels May 15, 2019
@nelsonic
Copy link
Member Author

Relevant test:

assert :error == Url.cast("www.test.com")

@nelsonic
Copy link
Member Author

nelsonic commented Dec 1, 2019

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 nelsonic added the help wanted Extra attention is needed label Dec 1, 2019
@ndrean
Copy link

ndrean commented Sep 23, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants