Skip to content

Easier way to check if a domain includes a valid TLD #27

@axelson

Description

@axelson

I have the given requirement, given an arbitrary string, check if any valid domains are listed in the string and highlight/linkify them. I already have a basic regex to split the string into potential domains.

I would like there to be a function in PublicSuffix that could more readily answer this. Right now I am using:

  @doc """
  Check if the given host contains a valid TLD that does not comprise the entire
  host (since we don't want to create a link to a TLD)
  """
  def valid_tld?(%URI{host: nil}), do: false
  def valid_tld?(%URI{host: host}) do
    rule = PublicSuffix.prevailing_rule(host)
    rule != "*" && rule != host
  end

Which I guess seems simple enough but it might be nice to have some sort of helper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions