getPath() public static method

public static getPath ( string $url ) : string
$url string
return string
Esempio n. 1
0
function clean($url, $list = [])
{
    // only hostnames & path
    $url = Domainparser::getHostname($url) . Domainparser::getPath($url);
    // delete redundant subdomains
    $root = Domainparser::getRootDomain($url);
    if (!empty($list) && $root !== Domainparser::getHostname($url) && in_array($root, $list)) {
        $url = '';
    }
    // trailing /
    $url = trim($url, '/');
    // lower case
    $url = strtolower($url);
    $url = trim($url);
    $punicode = new \TrueBV\Punycode();
    $url = iconv("UTF-8", "ISO-8859-1", $punicode->encode($url));
    return $url;
}
Esempio n. 2
0
 /**
  * @depends testRetrieveDomainlist
  */
 public function testBlocked()
 {
     $this->mockReferer(null);
     $this->assertFalse(Blocker::blocked(), 'Should not block unset referer');
     $this->mockReferer('');
     $this->assertFalse(Blocker::blocked(), 'Should not block empty referer');
     $this->mockReferer(self::INVALID_DOMAIN);
     $this->assertFalse(Blocker::blocked(), 'Should not block invalid referer');
     $badReferrals = $this->getBadReferrals();
     if (empty($badReferrals)) {
         $this->markTestIncomplete('Could not fetch bad referers for testing');
     }
     foreach ($badReferrals as $badReferral) {
         if ($badReferral && substr($badReferral, 0, 1) !== '#') {
             // Referer matches blocked domain exactly
             $this->mockReferer($badReferral);
             $this->assertTrue(Blocker::blocked(), 'Should block bad referer ' . $badReferral);
             // Hostname of referer matches blocked domain exactly
             $this->mockReferer('http://' . $badReferral);
             $this->assertTrue(Blocker::blocked(), 'Should block bad referer http://' . $badReferral);
             // Referer is a subdomain of blocked domain (only on root domains with no path)
             if (($root = Domainparser::getRootDomain($badReferral)) === $badReferral && !trim(Domainparser::getPath($badReferral), '/')) {
                 $this->mockReferer('http://test.' . $badReferral);
                 $this->assertTrue(Blocker::blocked(), 'Should block bad referer http://test.' . $badReferral . ' but it\'s not (' . Blocker::explain() . ')');
             }
             // Referer is a root domain of blocked subdomain
             if ($root !== $badReferral) {
                 $this->mockReferer($root);
                 $this->assertFalse(Blocker::blocked(), 'Should not block root domain ' . $root);
             }
         }
     }
     foreach ($this->goodReferrals as $goodReferral) {
         $this->mockReferer($goodReferral);
         $this->assertFalse(Blocker::blocked(), 'Should not block good referer ' . $goodReferral);
     }
 }