https://github.com/weppos/publicsuffix-ruby
Domain name parser for Ruby based on the Public Suffix List.
https://github.com/weppos/publicsuffix-ruby
Keywords
psl publicsuffix ruby
Keywords from Contributors
rubygem activerecord crash-reporting sinatra mvc activejob rspec rack feature-flag sidekiq
Last synced: about 19 hours ago
JSON representation
Repository metadata
Domain name parser for Ruby based on the Public Suffix List.
- Host: GitHub
- URL: https://github.com/weppos/publicsuffix-ruby
- Owner: weppos
- License: mit
- Created: 2009-11-01T14:59:38.000Z (over 16 years ago)
- Default Branch: main
- Last Pushed: 2026-03-01T17:06:24.000Z (4 days ago)
- Last Synced: 2026-03-01T19:36:30.897Z (4 days ago)
- Topics: psl, publicsuffix, ruby
- Language: Ruby
- Homepage: https://simonecarletti.com/code/publicsuffix-ruby
- Size: 1.76 MB
- Stars: 650
- Watchers: 13
- Forks: 110
- Open Issues: 5
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Security: SECURITY.md
- Agents: AGENTS.md
README.md
PublicSuffix for Ruby
PublicSuffix is a Ruby domain name parser based on the Public Suffix List.
Links
Requirements
PublicSuffix requires Ruby >= 3.2. For older versions of Ruby, use a previous release.
Installation
You can install the gem manually:
gem install public_suffix
Or use Bundler and define it as a dependency in your Gemfile:
gem 'public_suffix'
Usage
Extract the domain out from a name:
PublicSuffix.domain("google.com")
# => "google.com"
PublicSuffix.domain("www.google.com")
# => "google.com"
PublicSuffix.domain("www.google.co.uk")
# => "google.co.uk"
Parse a domain without subdomains:
domain = PublicSuffix.parse("google.com")
# => #<PublicSuffix::Domain>
domain.tld
# => "com"
domain.sld
# => "google"
domain.trd
# => nil
domain.domain
# => "google.com"
domain.subdomain
# => nil
Parse a domain with subdomains:
domain = PublicSuffix.parse("www.google.com")
# => #<PublicSuffix::Domain>
domain.tld
# => "com"
domain.sld
# => "google"
domain.trd
# => "www"
domain.domain
# => "google.com"
domain.subdomain
# => "www.google.com"
Simple validation example:
PublicSuffix.valid?("google.com")
# => true
PublicSuffix.valid?("www.google.com")
# => true
# Explicitly forbidden, it is listed as a private domain
PublicSuffix.valid?("blogspot.com")
# => false
# Unknown/not-listed TLD domains are valid by default
PublicSuffix.valid?("example.tldnotlisted")
# => true
Strict validation (without applying the default * rule):
PublicSuffix.valid?("example.tldnotlisted", default_rule: nil)
# => false
Fully qualified domain names
This library automatically recognizes Fully Qualified Domain Names. A FQDN is a domain name that ends with a trailing dot.
# Parse a standard domain name
PublicSuffix.domain("www.google.com")
# => "google.com"
# Parse a fully qualified domain name
PublicSuffix.domain("www.google.com.")
# => "google.com"
Private domains
This library supports toggling private (non-ICANN) domain handling.
# Extract a domain including private domains (by default)
PublicSuffix.domain("something.blogspot.com")
# => "something.blogspot.com"
# Extract a domain excluding private domains
PublicSuffix.domain("something.blogspot.com", ignore_private: true)
# => "blogspot.com"
# It also works for #parse and #valid?
PublicSuffix.parse("something.blogspot.com", ignore_private: true)
PublicSuffix.valid?("something.blogspot.com", ignore_private: true)
If you don't care about private domains at all, it's more efficient to exclude them when the list is parsed:
# Disable support for private TLDs
PublicSuffix::List.default = PublicSuffix::List.parse(File.read(PublicSuffix::List::DEFAULT_LIST_PATH), private_domains: false)
# => "blogspot.com"
PublicSuffix.domain("something.blogspot.com")
# => "blogspot.com"
Adding custom domains
To manually add a domain to the list:
PublicSuffix::List.default << PublicSuffix::Rule.factory('onmicrosoft.com')
What is the public suffix list?
The Public Suffix List is a cross-vendor initiative to provide an accurate list of domain name suffixes.
The Public Suffix List is an initiative of the Mozilla Project, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.
A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are ".com", ".co.uk" and "pvt.k12.wy.us". The Public Suffix List is a list of all known public suffixes.
Why use the public suffix list instead of regular expressions?
Previously, browsers used an algorithm which basically only denied setting wide-ranging cookies for top-level domains with no dots (e.g. com or org). However, this did not work for top-level domains where only third-level registrations are allowed (e.g. co.uk). In these cases, websites could set a cookie for co.uk which will be passed onto every website registered under co.uk.
Clearly, this was a security risk as it allowed websites other than the one setting the cookie to read it, and therefore potentially extract sensitive information.
Since there is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list of all top-level domains and the level at which domains can be registered. This is the aim of the effective TLD list.
As well as being used to prevent cookies from being set where they shouldn't be, the list can also potentially be used for other applications where the registry controlled and privately controlled parts of a domain name need to be known, for example when grouping by top-level domains.
Source: https://wiki.mozilla.org/Public_Suffix_List
Not convinced yet? Check out this real world example.
Does PublicSuffix make network requests?
No. PublicSuffix comes with a bundled list. It does not make any HTTP requests to parse or validate a domain.
Terminology
-
TLD (Top-Level Domain): The last segment of a domain name. For example, in
mozilla.org, the.orgportion is the TLD. -
SLD (Second-Level Domain): A domain directly below a top-level domain. For example, in
https://www.mozilla.org/en-US/,mozillais the second-level domain of the.orgTLD. -
TRD (Third-Level Domain): Also known as a subdomain, this is the part of the domain before the SLD or root domain. For example, in
https://www.mozilla.org/en-US/,wwwis the TRD. -
FQDN (Fully Qualified Domain Name): A complete domain name that includes the hostname, domain, and top-level domain, ending with a trailing dot. The format is
[hostname].[domain].[tld].(e.g.,www.mozilla.org.).
Documentation and support
Documentation
Library documentation is auto-generated from the README and source code, and is available at https://rubydoc.info/gems/public_suffix.
Bug reports and contributions
- Bug Tracker: https://github.com/weppos/publicsuffix-ruby/issues
- Code Repository: https://github.com/weppos/publicsuffix-ruby
Contributions are welcome! Please include tests and/or feature coverage for every patch, and create a topic branch for every separate change you make.
Enterprise support
Consider subscribing to Tidelift, which provides enterprise support for this project as part of the Tidelift Subscription. Tidelift subscriptions help fund the project, allowing us to ship releases, bugfixes, and security updates more frequently.
Security and vulnerability reporting
For full information and details about our security policy, please visit SECURITY.md.
Changelog
See CHANGELOG.md for details.
License
Copyright (c) 2009-2026 Simone Carletti. MIT License.
The Public Suffix List source is subject to the terms of the Mozilla Public License, v. 2.0.
Owner metadata
- Name: Simone Carletti
- Login: weppos
- Email:
- Kind: user
- Description: CTO at @dnsimple. Passionate programmer, tec/rec scuba instructor, sommelier. Interested in programming, internet protocols & online security.
- Website: https://simonecarletti.com
- Location: Rome, Italy
- Twitter: weppos
- Company: DNSimple
- Icon url: https://avatars.githubusercontent.com/u/5387?v=4
- Repositories: 103
- Last ynced at: 2023-04-09T03:48:46.040Z
- Profile URL: https://github.com/weppos
GitHub Events
Total
- Delete event: 100
- Pull request event: 219
- Fork event: 3
- Issues event: 9
- Watch event: 25
- Issue comment event: 7
- Push event: 147
- Create event: 120
Last Year
- Delete event: 65
- Pull request event: 148
- Fork event: 1
- Issues event: 9
- Watch event: 14
- Issue comment event: 6
- Push event: 93
- Create event: 87
Committers metadata
Last synced: 4 days ago
Total Commits: 995
Total Committers: 42
Avg Commits per committer: 23.69
Development Distribution Score (DDS): 0.382
Commits in past year: 158
Committers in past year: 3
Avg Commits per committer in past year: 52.667
Development Distribution Score (DDS) in past year: 0.316
| Name | Commits | |
|---|---|---|
| Simone Carletti | w****s@w****t | 615 |
| github-actions[bot] | 4****] | 275 |
| dependabot[bot] | 4****] | 29 |
| Postmodern | p****3@g****m | 19 |
| Camilo Lopez | c****z@w****m | 5 |
| Simone Carletti | w****s@g****m | 5 |
| Marc Seeger | m****l@m****e | 3 |
| Trevor Turk | t****k@g****m | 3 |
| dependabot-preview[bot] | 2****] | 3 |
| Peter Goldstein | p****n@g****m | 2 |
| Patrik Ragnarsson | p****k@s****t | 2 |
| James Dennes | j****s@g****m | 2 |
| Andrey Nering | a****y@n****r | 2 |
| Alex Smith | a****s@f****m | 2 |
| Rob Holland | r****b@c****m | 1 |
| Adam Niedzielski | a****y@g****m | 1 |
| Aki | a****n@g****m | 1 |
| Andrew Nesbitt | a****z@g****m | 1 |
| Benjamin Borowski | b****n@w****m | 1 |
| Brian Hawley | b****y@y****m | 1 |
| Charles Barbier | u****s@g****m | 1 |
| raeno | j****o@g****m | 1 |
| Yuichiro Kaneko | s****a@g****m | 1 |
| William Montgomery | w****y@g****m | 1 |
| William Montgomery | 8****k | 1 |
| Peter Cai | 2****i | 1 |
| Paweł Gościcki | p****i@g****m | 1 |
| Orien Madgwick | _@o****o | 1 |
| Olle Jonsson | o****n@g****m | 1 |
| Masato Nakamura | m****5@g****m | 1 |
| and 12 more... | ||
Committer domains:
- mcclymont.it: 1
- gam3.net: 1
- shopify.com: 1
- vzonneveld.nl: 1
- gmx.at: 1
- jonhue.me: 1
- me.com: 1
- leereilly.net: 1
- orien.io: 1
- weareokidoki.com: 1
- clearbit.com: 1
- fastmail.fm: 1
- nering.com.br: 1
- starkast.net: 1
- marc-seeger.de: 1
- websense.com: 1
- weppos.net: 1
Issue and Pull Request metadata
Last synced: about 23 hours ago
Total issues: 25
Total pull requests: 455
Average time to close issues: 3 months
Average time to close pull requests: 7 days
Total issue authors: 25
Total pull request authors: 36
Average comments per issue: 2.6
Average comments per pull request: 0.14
Merged pull request: 387
Bot issues: 1
Bot pull requests: 417
Past year issues: 1
Past year pull requests: 133
Past year average time to close issues: 13 days
Past year average time to close pull requests: about 17 hours
Past year issue authors: 1
Past year pull request authors: 2
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.01
Past year merged pull request: 108
Past year bot issues: 0
Past year bot pull requests: 133
Top Issue Authors
- gsar (1)
- dentarg (1)
- hmfarooq (1)
- rokkit (1)
- postmodern (1)
- BrianHawley (1)
- Nowaker (1)
- shweta-ms (1)
- MoralCode (1)
- tilo (1)
- github-actions[bot] (1)
- bastelfreak (1)
- nikita-nikolajev (1)
- ashmaroli (1)
- BillyParadise (1)
Top Pull Request Authors
- github-actions[bot] (380)
- dependabot[bot] (33)
- dependabot-preview[bot] (4)
- abhishekk1903 (2)
- andreynering (2)
- andrew (2)
- petergoldstein (2)
- sammo1235 (2)
- pzb (1)
- unixcharles (1)
- cseeman (1)
- martijnrusschen (1)
- harshvardhansharma (1)
- BanzaiMan (1)
- Pieparker (1)
Top Issue Labels
- enhancement (3)
- bug (2)
- question (2)
- task (1)
- psl (1)
Top Pull Request Labels
- psl (283)
- dependencies (37)
- enhancement (14)
- task (2)
- A:docs (2)
Package metadata
- Total packages: 3
-
Total downloads:
- rubygems: 2,204,438,463 total
- Total docker downloads: 7,458,332,076
- Total dependent packages: 149 (may contain duplicates)
- Total dependent repositories: 760,707 (may contain duplicates)
- Total versions: 188
- Total maintainers: 1
gem.coop: public_suffix
PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains.
- Homepage: https://simonecarletti.com/code/publicsuffix-ruby
- Documentation: http://www.rubydoc.info/gems/public_suffix/
- Licenses: MIT
- Latest release: 7.0.5 (published 2 days ago)
- Last Synced: 2026-03-04T01:01:57.506Z (1 day ago)
- Versions: 57
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 1,102,107,821 Total
- Docker Downloads: 3,729,166,038
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.007%
- Downloads: 0.012%
- Docker downloads count: 0.015%
- Maintainers (1)
-
Funding:
- https://github.com/sponsors/weppos
rubygems.org: public_suffix
PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains.
- Homepage: https://simonecarletti.com/code/publicsuffix-ruby
- Documentation: http://www.rubydoc.info/gems/public_suffix/
- Licenses: MIT
- Latest release: 7.0.5 (published 2 days ago)
- Last Synced: 2026-03-04T09:01:50.711Z (1 day ago)
- Versions: 57
- Dependent Packages: 149
- Dependent Repositories: 760,707
- Downloads: 1,102,330,642 Total
- Docker Downloads: 3,729,166,038
-
Rankings:
- Downloads: 0.016%
- Dependent repos count: 0.017%
- Docker downloads count: 0.028%
- Dependent packages count: 0.235%
- Average: 0.856%
- Stargazers count: 2.319%
- Forks count: 2.519%
- Maintainers (1)
-
Funding:
- https://github.com/sponsors/weppos
proxy.golang.org: github.com/weppos/publicsuffix-ruby
- Homepage:
- Documentation: https://pkg.go.dev/github.com/weppos/publicsuffix-ruby#section-documentation
- Licenses: mit
- Latest release: v7.0.5+incompatible (published 2 days ago)
- Last Synced: 2026-03-04T12:22:03.825Z (about 22 hours ago)
- Versions: 74
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 5.442%
- Average: 5.624%
- Dependent repos count: 5.807%
Dependencies
- memory_profiler >= 0
- minitest >= 0
- minitest-reporters >= 0
- mocha >= 0
- rake >= 0
- rubocop ~> 0.90
- yard >= 0
- actions/checkout v3 composite
- peter-evans/create-pull-request v4 composite
- ruby/setup-ruby v1 composite
- actions/checkout v3 composite
- cadwallion/publish-rubygems-action d9474d9633f4674e59afb0c343f2dafe25181328 composite
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
Score: 33.21393059043775