Skip to content

URL with without https:// fails #34

Open

Description

@nelsonic

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?

Activity

  1. nelsonic commented on May 15, 2019

    @nelsonic
    MemberAuthor

    Relevant test:

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

  2. nelsonic commented on Dec 1, 2019

    @nelsonic
    MemberAuthor

    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.

  3. ndrean commented on Sep 23, 2023

    @ndrean

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    discusshelp wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions