Skip to content

Commit

Permalink
Use . instead of null in search list by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jun 2, 2024
1 parent 089f445 commit 91e5017
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/DnsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function __construct(array $nameservers, array $knownHosts = [])
public function withSearchList(array $searchList): self
{
$self = clone $this;
$self->searchList = $searchList;

// Replace null with '.' for backward compatibility
$self->searchList = \array_map(fn ($search) => $search ?? '.', $searchList);

return $self;
}
Expand Down
15 changes: 9 additions & 6 deletions src/Rfc1035StubDnsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,23 @@ public function resolve(string $name, ?int $typeRestriction = null, ?Cancellatio

\assert($this->config !== null);

$searchList = [null];
$searchList = ['.'];
if (!$trailingDot && $dots < $this->config->getNdots()) {
$searchList = \array_merge($this->config->getSearchList(), $searchList);
$configuredSearchList = $this->config->getSearchList();
if (\in_array('.', $configuredSearchList, true)) {
$searchList = $configuredSearchList;
} else {
$searchList = \array_merge($configuredSearchList, $searchList);
}
}

$sendQuery = $this->query(...);

foreach ($searchList as $searchIndex => $search) {
for ($redirects = 0; $redirects < 5; $redirects++) {

$searchName = match ($search) {
null => $name,
"." => $name . ".",
default => $name . "." . $search,
'.' => \rtrim($name, '.') . '.',
default => $name . '.' . $search,
};

try {
Expand Down

0 comments on commit 91e5017

Please sign in to comment.