Skip to content

Commit

Permalink
Validate name format in private method
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveRandom committed Jun 16, 2014
1 parent 6174dfd commit 5a5610a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/Addr/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ public function __construct(
}
}

/**
* Verify the supplied domain name is in a valid format
*
* @param $name
* @param $callback
* @return bool
*/
private function validateName($name, $callback)
{
if (!$this->nameValidator->validate($name)) {
$this->reactor->immediately(function() use($callback) {
call_user_func($callback, null, ResolutionErrors::ERR_INVALID_NAME);
});

return false;
}

return true;
}

/**
* Check if a supplied name is an IP address and resolve immediately
*
Expand Down Expand Up @@ -183,11 +203,8 @@ public function resolve($name, callable $callback, $mode = 3)
return;
}

if (!$this->nameValidator->validate($name)) {
$this->reactor->immediately(function() use($callback) {
call_user_func($callback, null, ResolutionErrors::ERR_INVALID_NAME);
});

$name = strtolower($name);
if (!$this->validateName($name, $callback)) {
return;
}

Expand Down

0 comments on commit 5a5610a

Please sign in to comment.