internal/parser: add PublicSuffix and RegisteredDomain methods to List #2228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These calculate the public suffix or registered/registerable domain of some input domain, according to the strict PSL algorithm. Aside from being useful as a reference implementation of the algorithm, it comes in handy in validations that need to do stuff like figure out what registry to query for domain info.
Please check my work carefully on the PSL algorithm, in particular the handling of wildcard domains. I read the spec very carefully and also the platform.sh wiki page, and I think I've correctly implemented the strict PSL algorithm with no deviation (a public suffix
*.foo.com
does not imply a public suffixfoo.com
, and there is an implicit hardcoded*
public suffix so that all unknown TLDs are automatically public suffixes).Later on I could add modifiers to these methods to implement the variants as well, but for now I stuck to the reference algorithm. I ended up needing this logic to implement RDAP support for checking domain expiry, since I have to map a random PSL entry to "which registry RDAP service should I query", and for some suffixes that requires computing the "next" public suffix of the PSL entry :)