GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - reisub/public_sufx: Elixir library providing public suffix logic based on publicsuffix.org data

BranchesTags
Open more actions menu

Latest commit

 

History

193 Commits
193 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
config
config
 
 
data
data
 
 
lib
lib
 
 
test
test
 
 
.credo.exs
.credo.exs
 
 
.doctor.exs
.doctor.exs
 
 
.formatter.exs
.formatter.exs
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mise.toml
mise.toml
 
 
mix.exs
mix.exs
 
 
mix.lock
mix.lock
 
 

Repository files navigation

PublicSufx

CI License Version Hex Docs

PublicSufx is an Elixir library to operate on domain names using the public suffix rules provided by https://publicsuffix.org/:

A "public suffix" is one under which Internet users can (or historically could) directly register names. Some examples of public suffixes are .com, .co.uk and pvt.k12.ma.us. The Public Suffix List is a list of all known public suffixes.

This Elixir library provides a means to get the public suffix from any domain:

iex(1)> PublicSufx.public_suffix("mysite.foo.bar.com")
"com"
iex(2)> PublicSufx.public_suffix("mysite.foo.bar.co.uk")
"co.uk"

... and a way to check if a domain is a public suffix:

iex(1)> PublicSufx.public_suffix?("mysite.foo.bar.co.uk")
false
iex(2)> PublicSufx.public_suffix?("co.uk")
true

Domains are canonicalized before matching, so case, a trailing dot, Unicode normalization forms and IDNA dot variants (。, ., 。) don't change the result:

iex(1)> PublicSufx.public_suffix?("GitHub.io.")
true
iex(2)> PublicSufx.public_suffix("foo。github。io")
"github.io"

Input that can't be a domain name (a leading dot, more than 4096 bytes or invalid UTF-8) returns nil, and public_suffix?/1 returns false for it. If you use public_suffix?/1 to reject public suffixes, validate the hostname as well.

The publicsuffix.org data file contains both official ICANN records and private records:

ICANN domains are those delegated by ICANN or part of the IANA root zone database. The authorized registry may express further policies on how they operate the TLD, such as subdivisions within it. Updates to this section can be submitted by anyone, but if they are not an authorized representative of the registry then they will need to back up their claims of error with documentation from the registry's website.

PRIVATE domains are amendments submitted by the domain holder, as an expression of how they operate their domain security policy. Updates to this section are only accepted from authorized representatives of the domain registrant. This is so we can be certain they know what they are getting into.

Working with Rules

You can also gain access to the prevailing rule for a particular domain:

iex(1)> PublicSufx.prevailing_rule("mysite.foo.bar.com")
"com"
iex(2)> PublicSufx.prevailing_rule("mysite.example")
"*"

Installation

The package can be installed by adding public_sufx to your list of dependencies in mix.exs:

def deps do
  [
    {:public_sufx, "~> 0.8.0"}
  ]
end

PublicSufx requires Elixir 1.15 or later and OTP 26 or later.

Configuration

PublicSufx is bundled with a cached copy of the public suffix list from publicsuffix.org and can be configured to download a fresh copy of the list on compilation by adding this in your config.exs:

config :public_sufx, download_data_on_compile: true

There are pros and cons to both approaches; which you choose will depend on the needs of your project:

  • Setting download_data_on_compile to true will ensure that the rules are always up-to-date (as of the time you last compiled) but could introduce an instability. While we have tried to implement the logic in this library according to the publicsuffix.org spec, one can imagine future rule changes not being handled properly by the existing logic and manifesting itself in a new bug.
  • Setting download_data_on_compile to false (or not setting it at all) ensures stable, consistent behavior. In the context of your project, you may want compilation to be deterministic. Compilation is also a bit faster when a new copy of the rules is not downloaded.

About

Elixir library providing public suffix logic based on publicsuffix.org data

Resources

Readme
MIT license
Activity

Stars

7 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.