Skip to content

Commit f06c740

Browse files
committed
ResolvedDomain should handle domain with root label
1 parent d806917 commit f06c740

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ supported type to avoid unexpected results. By default, if the input is not a
228228
`Pdp\Suffix` instance, the resulting public suffix will be labelled as
229229
being unknown. For more information go to the [Public Suffix section](#public-suffix)
230230

231-
> [!TIP]
231+
> [!NOTE]
232232
> Since version `6.4` Domain resolution is also adapted so that absolute domain
233233
can effectively be resolved. Prior to version `6.4` an exception was thrown.
234234

src/DomainName.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
* @see https://tools.ietf.org/html/rfc5890
1515
*
1616
* @extends IteratorAggregate<string>
17-
*
18-
* @method bool isAbsolute() tells whether the domain is absolute or not.
19-
* @method self withRootLabel() returns an instance with its Root label. (see https://tools.ietf.org/html/rfc3986#section-3.2.2)
20-
* @method self withoutRootLabel() returns an instance without its Root label. (see https://tools.ietf.org/html/rfc3986#section-3.2.2)
2117
*/
2218
interface DomainName extends Host, IteratorAggregate
2319
{

src/Host.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
* @see https://tools.ietf.org/html/rfc1034#section-3.5
1212
* @see https://tools.ietf.org/html/rfc1123#section-2.1
1313
* @see https://tools.ietf.org/html/rfc5890
14+
*
15+
* @method bool isAbsolute() tells whether the domain is absolute or not.
16+
* @method static withRootLabel() returns an instance with its Root label. (see https://tools.ietf.org/html/rfc3986#section-3.2.2)
17+
* @method static withoutRootLabel() returns an instance without its Root label. (see https://tools.ietf.org/html/rfc3986#section-3.2.2)
1418
*/
1519
interface Host extends Countable, JsonSerializable
1620
{

src/ResolvedDomain.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ public function toUnicode(): self
190190
return new self($this->domain->toUnicode(), $this->suffix->toUnicode());
191191
}
192192

193+
public function isAbsolute(): bool
194+
{
195+
return $this->domain->isAbsolute();
196+
}
197+
198+
public function withoutRootLabel(): self
199+
{
200+
return new self($this->domain->withoutRootLabel(), $this->suffix);
201+
}
202+
203+
public function withRootLabel(): self
204+
{
205+
return new self($this->domain->withRootLabel(), $this->suffix);
206+
}
207+
193208
/**
194209
* @throws CannotProcessHost
195210
*/

src/ResolvedDomainTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,19 @@ public function testSuffixCanHandleIpLikeValue(): void
628628
ResolvedDomain::fromICANN('cloudflare-dns.com.1.1.1.1', 4)->toString()
629629
);
630630
}
631+
632+
public function testWithAndWithoutRootLabelResult(): void
633+
{
634+
$withoutRootLabelResult = ResolvedDomain::fromICANN('cloudflare-dns.com', 1);
635+
$withRootLabelResult = $withoutRootLabelResult->withRootLabel();
636+
637+
self::assertTrue($withRootLabelResult->isAbsolute());
638+
self::assertFalse($withoutRootLabelResult->isAbsolute());
639+
self::assertEquals($withoutRootLabelResult, $withRootLabelResult->withoutRootLabel());
640+
self::assertSame($withoutRootLabelResult->suffix()->value(), $withRootLabelResult->suffix()->value());
641+
self::assertSame($withoutRootLabelResult->subDomain()->value(), $withRootLabelResult->subDomain()->value());
642+
self::assertSame($withoutRootLabelResult->registrableDomain()->value(), $withRootLabelResult->registrableDomain()->value());
643+
self::assertSame($withoutRootLabelResult->secondLevelDomain()->value(), $withRootLabelResult->secondLevelDomain()->value());
644+
self::assertNotSame($withoutRootLabelResult->domain()->value(), $withRootLabelResult->domain()->value());
645+
}
631646
}

0 commit comments

Comments
 (0)