io-developer / php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 8.0 compatible (5.4+ old versions)
MIT License
440 stars 118 forks source link

Module throwing an exception when using loadDomainInfo #94

Closed hlorofos closed 3 years ago

hlorofos commented 4 years ago

PHP-Whois version: 3.4.3

PHP version: 7.3.9

Description

Module is throwing exception when using loadDomainInfo ErrorException: Array to string conversion in /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Helpers/GroupHelper.php:142

How to reproduce

        $whois = Whois::create();
        $info = $whois->loadDomainInfo('megasoriana.com');

Additional context

#1 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Helpers/GroupHelper.php(142): preg_replace_callback('~\\$[a-z\\d]+~ui', Object(Closure), '$id')
--
#2 [internal function]: Iodev\Whois\Helpers\GroupHelper::Iodev\Whois\Helpers\{closure}('$id', 'nic-hdl')
#3 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Helpers/GroupHelper.php(146): array_walk_recursive(Array, Object(Closure))
#4 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Helpers/GroupFilter.php(42): Iodev\Whois\Helpers\GroupHelper::renderSubsets(Array, Array)
#5 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Modules/Tld/Parsers/BlockParser.php(238): Iodev\Whois\Helpers\GroupFilter->filterHasSubsetOf(Array)
#6 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Modules/Tld/Parsers/BlockParser.php(102): Iodev\Whois\Modules\Tld\Parsers\BlockParser->parseOwner(Object(Iodev\Whois\Helpers\GroupFilter), Object(Iodev\Whois\Helpers\GroupFilter))
#7 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Modules/Tld/Parsers/AutoParser.php(51): Iodev\Whois\Modules\Tld\Parsers\BlockParser->parseResponse(Object(Iodev\Whois\Modules\Tld\DomainResponse))
#8 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Modules/Tld/TldModule.php(211): Iodev\Whois\Modules\Tld\Parsers\AutoParser->parseResponse(Object(Iodev\Whois\Modules\Tld\DomainResponse))
#9 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Modules/Tld/TldModule.php(228): Iodev\Whois\Modules\Tld\TldModule->loadParsedTo(Object(Iodev\Whois\Modules\Tld\DomainResponse), NULL, Object(Iodev\Whois\Modules\Tld\TldServer), 'megasoriana.com', false, 'whois.akky.mx', NULL)
#10 /var/www/vendor/io-developer/php-whois/src/Iodev/Whois/Modules/Tld/TldModule.php(185): Iodev\Whois\Modules\Tld\TldModule->loadParsedTo(Object(Iodev\Whois\Modules\Tld\DomainResponse), Object(Iodev\Whois\Modules\Tld\DomainInfo), Object(Iodev\Whois\Modules\Tld\TldServer), 'megasoriana.com', false, 'whois.akky.mx', NULL)
zaherg commented 3 years ago

The main cause of this error is related to parsing the owner function

in Iodev\Whois\Modules\Tld\Parsers\BlockParser the function is :

    protected function parseOwner(GroupFilter $rootFilter, GroupFilter $primaryFilter)
    {
        $owner = $rootFilter->cloneMe()
            ->useMatchFirstOnly(true)
            ->filterHasSubsetOf($this->ownerSubsets)
            ->toSelector()
            ->selectKeys($this->ownerKeys)
            ->getFirst('');

        if (empty($owner)) {
            $owner = $primaryFilter->toSelector()
                ->selectKeys($this->ownerKeys)
                ->getFirst('');
        }
        if (!empty($owner)) {
            $owner = $rootFilter->cloneMe()
                ->setSubsetParams(['$id' => $owner])
                ->useMatchFirstOnly(true)
                ->filterHasSubsetOf($this->contactSubsets)
                ->toSelector()
                ->selectKeys($this->contactOrgKeys)
                ->selectItems([ $owner ])
                ->removeEmpty()
                ->getFirst('');
        }
        return $owner;
    }

now this section

        if (!empty($owner)) {
            $owner = $rootFilter->cloneMe()
                ->setSubsetParams(['$id' => $owner])
                ->useMatchFirstOnly(true)
                ->filterHasSubsetOf($this->contactSubsets)
                ->toSelector()
                ->selectKeys($this->contactOrgKeys)
                ->selectItems([ $owner ])
                ->removeEmpty()
                ->getFirst('');
        }

is the one which throw the error if the $owner data was an array, the simple fix would be to change the if statement to something like

        if (!empty($owner) && !is_array($owner)) {

for sure this is a duck-tape solution, which needs to be investigated more

io-developer commented 3 years ago

Can't reproduce. Possibly already fixed in master after parsing improvements.