jeremykendall / php-domain-parser

Public Suffix List based domain parsing implemented in PHP
MIT License
1.16k stars 128 forks source link

Private domains containing multi-level suffixes are unresolvable #334

Closed laurynasgadl closed 2 years ago

laurynasgadl commented 2 years ago

Issue summary

The changes introduced with https://github.com/jeremykendall/php-domain-parser/pull/322 broke the resolution of private domains that contain valid higher-level suffixes.

For example, consider the TLD eu.org - it is listed as a valid private domain, but it is also a part of other valid private domains:

// EU.org https://eu.org/
// Submitted by Pierre Beyssac <hostmaster@eu.org>
eu.org
al.eu.org
asso.eu.org
at.eu.org
au.eu.org
...

After the changes in https://github.com/jeremykendall/php-domain-parser/pull/322, domains such as test-domain.eu.org are not recognised as private domains: PHP Fatal error: Uncaught Pdp\UnableToResolveDomain: The domain "test-domain.eu.org" does not contain a "private" TLD.

Only lower-level entries, such as test-domain.au.eu.org are recognised properly.

System informations

Information Description
Pdp version 6.1.1
PHP version *
OS Platform *

Standalone code, or other way to reproduce the problem

$domain = $publicSuffixList->getPrivateDomain("test-domain.eu.org");
die('private domain', json_encode([
    'domain' => $domain->domain(),
    'subdomain' => $domain->subDomain(),
    'registrable_domain' => $domain->registrableDomain(),
    'second_level_domain' => $domain->secondLevelDomain(),
]));

Expected result

private domain {"domain":"test-domain.eu.org","subdomain":null,"registrable_domain":"test-domain.eu.org","second_level_domain":"test-domain"}

Actual result

PHP Fatal error: Uncaught Pdp\UnableToResolveDomain: The domain "test-domain.eu.org" does not contain a "private" TLD.

nyamsprod commented 2 years ago

FYI: the fix targets the next minor release which drops PHP7 and PHP8.0 supports but once accepted I can back-port it to a 6.1.x release if needed.

nyamsprod commented 2 years ago

resolved via #336