GithubHelp home page GithubHelp logo

thephpleague / uri-hostname-parser Goto Github PK

View Code? Open in Web Editor NEW
198.0 6.0 5.0 909 KB

A lightweight hostname parser according to public suffix list ICANN section

Home Page: https://uri.thephpleague.com/domain-parser/

License: MIT License

PHP 100.00%
psl psl-icann hostname uri icann psl-rules php

uri-hostname-parser's Introduction

Uri Hostname Parser

This package is EOL since 2018-02-16

This repository was a temporary workaround for

You should instead use:

Build Status Latest Version

This package contains a lightweight domain parser using the Public Suffix List (PSL) ICANN section based on the excellent work by Jeremy Kendall.

WARNING: Some people use the PSL to determine what is a valid domain name and what isn't. This is dangerous, particularly in these days where new gTLDs are arriving at a rapid pace, if your software does not regularly receive PSL updates, because it will erroneously think new gTLDs are not valid. The DNS is the proper source for this in normal condition. If you must use it for this purpose, please do not bake static copies of the PSL into your software with no update mechanism.

System Requirements

You need:

  • PHP >= 7.0 but the latest stable version of PHP is recommended
  • the mbstring extension
  • the intl extension
  • the curl extension

Dependencies

Installation

$ composer require league/uri-hostname-parser

Documentation

Full documentation can be found at uri.thephpleague.com.

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING and CONDUCT for details.

Testing

Uri Hostname Parser has a PHPUnit test suite and a coding style compliance test suite using PHP CS Fixer. To run the tests, run the following command from the project folder.

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Attribution

This work is based on a Fork of PHP Domain Parser

uri-hostname-parser's People

Contributors

arendjantetteroo avatar geekwright avatar huglester avatar irfanevrens avatar jeremykendall avatar mikegreiling avatar nyamsprod avatar saeven avatar samsonasik avatar steffenweber avatar stylet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

uri-hostname-parser's Issues

za.net and za.org domains are not being correctly detected

Issue summary

za.net and za.org domains are not being correctly detected

Using the Host class I started seeing unexpected results when trying to extract information for za.org and za.net domains.

The below code:

$host = new Host('example.za.org');

returned:

array(7) {
  ["component"]=>
  string(14) "example.za.net"
  ["labels"]=>
  array(3) {
    [0]=>
    string(3) "net"
    [1]=>
    string(2) "za"
    [2]=>
    string(7) "example"
  }
  ["is_absolute"]=>
  bool(false)
  ["isPublicSuffixValid"]=>
  bool(true)
  ["publicSuffix"]=>
  string(3) "net"
  ["registrableDomain"]=>
  string(6) "za.net"
  ["subDomain"]=>
  string(7) "example"
}
Information Description
League\Uri\PublicSuffix version 5.3
PHP version 7.5.2
OS Platform Ubuntu 18.04 LTS

Standalone code, or other way to reproduce the problem

I modified an example from http://uri.thephpleague.com/5.0/publicsuffix/rules/ to test

<?php
require __DIR__.'/vendor/autoload.php';

use League\Uri\PublicSuffix\Cache;
use League\Uri\PublicSuffix\CurlHttpClient;
use League\Uri\PublicSuffix\ICANNSectionManager;

$manager = new ICANNSectionManager(new Cache(), new CurlHttpClient());
$icann_rules = $manager->getRules('https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat');
//$icann_rules is a League\Uri\PublicSuffix\Rules object

$domain = $icann_rules->resolve('example.za.net');
var_dump($domain->getDomain());            //returns 'example.za.net'
var_dump($domain->getPublicSuffix());      //returns 'net'
var_dump($domain->getRegistrableDomain()); //returns 'za.net'
var_dump($domain->getSubDomain());         //returns 'example'
var_dump($domain->isValid());              //returns true

Expected result

$domain = $icann_rules->resolve('example.za.net');
var_dump($domain->getDomain());            //returns 'example.za.net'
var_dump($domain->getPublicSuffix());      //returns 'za.net'
var_dump($domain->getRegistrableDomain()); //returns 'example.za.net'
var_dump($domain->getSubDomain());         //returns NULL
var_dump($domain->isValid());              //returns true

Actual result

$domain = $icann_rules->resolve('example.za.net');
var_dump($domain->getDomain());            //returns 'example.za.net'
var_dump($domain->getPublicSuffix());      //returns 'net'
var_dump($domain->getRegistrableDomain()); //returns 'za.net'
var_dump($domain->getSubDomain());         //returns 'example'
var_dump($domain->isValid());              //returns true

Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 34

Issue summary

Hi, I am trying to install a php yii template (https://youdate.hauntd.me/documentation/installation.html) and after installing the dependencies when I try to move the files to my development web root it shows an error in the browser.

So, when I try to see the apache logs I see -

Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 34

I think it might have to do something with my development hostname and so I tried to update the /etc/hosts file but it didn't help.
It would be great if you have anything that could help in fixing / further debugging of this issue
Also, please let me know if I can provide any other information that could help fixing this

System informations

Information Description
League\Uri\PublicSuffix 1.1.0
PHP 7.1
OS Ubuntu 16.04

Standalone code, or other way to reproduce the problem

https://youdate.hauntd.me/documentation/installation.html

Expected result

Web application preview in development environment

Actual result

Warning: Unsupported declare 'strict_types' in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 15

Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 34

How can I change the manager used by League\Uri\resolve_domain function?

Issue summary

I've league/uri-hostname-parser downloaded as a dependency and my vendor directory is not writable, so the cache used by the default manager created in League\Uri\resolve_domain function throws an exception. How can I change the manager which is being used there?

System informations

Information Description
League\Uri\PublicSuffix version could not find any package named PublicSuffix
PHP version 7.1.+
OS Platform Mac OS, Linux

League\Uri packages installed:

league/uri                                       5.2.0   URI manipulation library
league/uri-components                            1.6.0   URI components manipulation library
league/uri-hostname-parser                       1.0.4   ICANN base hostname parsing implemented in PHP.
league/uri-interfaces                            1.0.0   Common interface for URI representation
league/uri-manipulations                         1.3.0   URI manipulation library
league/uri-parser                                1.3.0   userland URI parser RFC 3986 compliant
league/uri-schemes                               1.1.1   URI manipulation library

Standalone code, or other way to reproduce the problem

  1. Install as a dependency in a project
  2. Make vendor directory not writable (chmod 555 -R vendor should do)
  3. Call League\Uri\resolve_domain function

Expected result

The function returns Domain object.

Actual result

The function throws an exception, stacktraces included in the following issues:

Failed to download league/uri-hostname-parser from dist...

Issue summary

  - Removing jeremykendall/php-domain-parser (3.0.0)
  - Installing league/uri-hostname-parser (1.0.0): Downloading (100%)

 Failed to download league/uri-hostname-parser from dist: The archive may contain identical file names with different capitalization (which fails on
 case insensitive filesystems): ZipArchive::extractTo(.../vendor/composer/554ec116/thephpleague-uri-hostname-pa
rser-e8d579d\data/leaguepsl::ICANN-SECTION-5a3cc7f81795bb2e48e848af42d287b4.cache): failed to open stream: Invalid argument
    Now trying to download from source

...

- Installing league/uri-hostname-parser (1.0.0): Cloning e8d579d034 from cache


  [RuntimeException]
  Failed to clone https://github.com/thephpleague/uri-hostname-parser.git via https, ssh protocols, aborting.
  - https://github.com/thephpleague/uri-hostname-parser.git
    fatal: destination path '...\vendor\league\uri-hostname-parser' already exists and is not an empty directory.
  - [email protected]:thephpleague/uri-hostname-parser.git
    fatal: destination path '...\vendor\league\uri-hostname-parser' already exists and is not an empty directory.

System informations

(In case of a bug report Please complete the table below)

Information Description
League\Uri\PublicSuffix version
PHP version 7.0
OS Platform Windows 7

Standalone code, or other way to reproduce the problem

 composer update --prefer-dist --ignore-platform-reqs --no-dev --no-progress --no-interaction --no-suggest --optimize-autoloader

Expected result

Actual result

The exception message 'Unable to load the public suffix list rules for %s' is ambiguous

Issue summary

getRules() in ICANNSectionManager throws an exception with the message 'Unable to load the public suffix list rules for %s'. The exception is thrown either if there is a problem retrieving the content via the httpClient or if there is a problem setting the cache. The exception message makes it appear as if the problem is is always with the httpclient.

Should the exception message be expanded to be more descriptive or an additional exception raised in the case of a cache fault?

Error when running in Laravel Vapor (AWS Lambda) Environment

Issue summary

Library works in dev and plain ol' VPS environment but fails using the new Laravel Vapor environment based on AWS Lambda.

System informations

(In case of a bug report Please complete the table below)

Information Description
League\Uri\PublicSuffix version 1.1.1
PHP version 7.3.9
OS Platform Laravel Vapor/AWS Lambda

Standalone code, or other way to reproduce the problem

$host = new Host(Http::createFromString(request()->getUri())->getHost());
$subdomain = $host->getSubDomain();

Expected result

To not throw an exception and to return the subdomain.

Actual result

Here is my Sentry stack trace:

Exception(most recent call first)

League\Uri\PublicSuffix\Exception: Unable to load the public suffix list rules for https://publicsuffix.org/list/public_suffix_list.dat
#66 /vendor/league/uri-hostname-parser/src/PublicSuffix/ICANNSectionManager.php(70): League\Uri\PublicSuffix\ICANNSectionManager::getRules
#65 /vendor/league/uri-components/src/Components/Host.php(459): League\Uri\Components\Host::lazyloadInfo
#64 /vendor/league/uri-components/src/Components/Host.php(425): League\Uri\Components\Host::__debugInfo
#63 /vendor/symfony/var-dumper/Caster/Caster.php(86): Symfony\Component\VarDumper\Caster\Caster::castObject
#62 /vendor/symfony/var-dumper/Cloner/AbstractCloner.php(319): Symfony\Component\VarDumper\Cloner\AbstractCloner::castObject
#61 /vendor/symfony/var-dumper/Cloner/VarCloner.php(189): Symfony\Component\VarDumper\Cloner\VarCloner::doClone
#60 /vendor/symfony/var-dumper/Cloner/AbstractCloner.php(257): Symfony\Component\VarDumper\Cloner\AbstractCloner::cloneVar
#59 /vendor/beyondcode/laravel-dump-server/src/Dumper.php(39): BeyondCode\DumpServer\Dumper::dump
#58 /vendor/beyondcode/laravel-dump-server/src/DumpServerServiceProvider.php(53): BeyondCode\DumpServer\DumpServerServiceProvider::BeyondCode\DumpServer\{closure}
#57 /vendor/symfony/var-dumper/VarDumper.php(46): Symfony\Component\VarDumper\VarDumper::dump
#56 /vendor/symfony/var-dumper/Resources/functions/dump.php(20): dump
#55 /routes/web.php(17): Illuminate\Routing\RouteFileRegistrar::{closure}
#54 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route::runCallable
#53 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(179): Illuminate\Routing\Route::run
#52 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\Routing\Router::Illuminate\Routing\{closure}
#51 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#50 /app/Http/Middleware/AddTenantMiddleware.php(86): App\Http\Middleware\AddTenantMiddleware::handle
#49 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#48 /vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Middleware\SubstituteBindings::handle
#47 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#46 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(76): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::handle
#45 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#44 /vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\View\Middleware\ShareErrorsFromSession::handle
#43 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#42 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\Session\Middleware\StartSession::handle
#41 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#40 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::handle
#39 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#38 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Cookie\Middleware\EncryptCookies::handle
#37 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#36 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline::then
#35 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\Routing\Router::runRouteWithinStack
#34 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\Routing\Router::runRoute
#33 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\Routing\Router::dispatchToRoute
#32 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\Routing\Router::dispatch
#31 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Foundation\Http\Kernel::Illuminate\Foundation\Http\{closure}
#30 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#29 /vendor/kabbouchi/nova-impersonate/src/Http/Middleware/Impersonate.php(24): KABBOUCHI\NovaImpersonate\Http\Middleware\Impersonate::handle
#28 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#27 /vendor/laravel/nova/src/Http/Middleware/ServeNova.php(26): Laravel\Nova\Http\Middleware\ServeNova::handle
#26 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#25 /vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(58): Barryvdh\Debugbar\Middleware\InjectDebugbar::handle
#24 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#23 /vendor/fideloper/proxy/src/TrustProxies.php(57): Fideloper\Proxy\TrustProxies::handle
#22 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#21 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Foundation\Http\Middleware\TransformsRequest::handle
#20 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#19 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Foundation\Http\Middleware\TransformsRequest::handle
#18 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#17 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Foundation\Http\Middleware\ValidatePostSize::handle
#16 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#15 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::handle
#14 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#13 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline::then
#12 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Foundation\Http\Kernel::sendRequestThroughRouter
#11 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel::handle
#10 /vendor/laravel/vapor-core/src/Runtime/HttpKernel.php(60): Laravel\Vapor\Runtime\HttpKernel::Laravel\Vapor\Runtime\{closure}
#9 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#8 /vendor/laravel/vapor-core/src/Runtime/Http/Middleware/EnsureVanityUrlIsNotIndexed.php(16): Laravel\Vapor\Runtime\Http\Middleware\EnsureVanityUrlIsNotIndexed::handle
#7 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#6 /vendor/laravel/vapor-core/src/Runtime/Http/Middleware/RedirectStaticAssets.php(30): Laravel\Vapor\Runtime\Http\Middleware\RedirectStaticAssets::handle
#5 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#4 /vendor/laravel/vapor-core/src/Runtime/Http/Middleware/EnsureOnNakedDomain.php(25): Laravel\Vapor\Runtime\Http\Middleware\EnsureOnNakedDomain::handle
#3 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#2 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline::then
#1 /vendor/laravel/vapor-core/src/Runtime/HttpKernel.php(61): Laravel\Vapor\Runtime\HttpKernel::handle
#0 /httpHandler.php(58): null

Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 34

Issue summary

Hi, I am trying to install a php yii template (https://youdate.hauntd.me/documentation/installation.html) and after installing the dependencies when I try to move the files to my development web root it shows an error in the browser.

So, when I try to see the apache logs I see -

Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 34

I think it might have to do something with my development hostname and

System informations

Information Description
League\Uri\PublicSuffix 1.1.0
PHP 7.1
OS Ubuntu 16.04

Standalone code, or other way to reproduce the problem

https://youdate.hauntd.me/documentation/installation.html

Expected result

Web application preview in development environment

Actual result

Warning: Unsupported declare 'strict_types' in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 15

Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/html/application/vendor/league/uri-hostname-parser/src/functions.php on line 34

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.