Giter Site home page Giter Site logo

Comments (4)

sitch avatar sitch commented on August 12, 2024 1

I used something like this:

  @spec valid_url?(any()) :: boolean()
  def valid_url?(url) when is_binary(url) do
    case URI.parse(url) do
      %URI{host: nil} -> false
      %URI{scheme: nil} -> false
      %URI{} -> true
    end
  end

  def valid_url?(_), do: false

from ecto_fields.

joeapearson avatar joeapearson commented on August 12, 2024

Actually, looking at the code it seems like there are probably a great deal of valid URLs that wouldn't be correctly treated. However what EctoFields is doing is a sensible default for a great deal of use cases, was that the original intention?

Suitable fixes that I can think of:

  • Update EctoFields.URL to accept all valid URLs. AFAIK this is much more involved than it sounds. But there might be some work that could be borrowed from https://mathiasbynens.be/demo/url-regex for example.
  • Update EctoFields.URL to accept some sort of per-field configuration allowing a user to customise the validation behaviour of URLs.

from ecto_fields.

brettinternet avatar brettinternet commented on August 12, 2024

EctoFields.URL also doesn't support IP addresses for a host.

EctoFields.IP.cast("http://1.1.1.1")
:error

from ecto_fields.

jerel avatar jerel commented on August 12, 2024

I've added support for ports and IP addresses via these commits 7d39c88...master

@joeapearson Yes, the idea is to have sensible handling for most use cases. In your estimation is the current implementation too restrictive or too permissive?

from ecto_fields.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.