Example #1
0
 /**
  * Tests the canonicalizing URL's
  */
 public function testCanonicalize()
 {
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host/%25%32%35"), "http://host/%25");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host/%25%32%35%25%32%35"), "http://host/%25%25");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host/%2525252525252525"), "http://host/%25");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host/asdf%25%32%35asd"), "http://host/asdf%25asd");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host/%%%25%32%35asd%%"), "http://host/%25%25%25asd%25%25");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com/"), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://%31%36%38%2e%31%38%38%2e%39%39%2e%32%36/%2E%73%65%63%75%72%65/%77%77%77%2E%65%62%61%79%2E%63%6F%6D/"), "http://168.188.99.26/.secure/www.ebay.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://195.127.0.11/uploads/%20%20%20%20/.verify/.eBaysecure=updateuserdataxplimnbqmn-xplmvalidateinfoswqpcmlx=hgplmcx/"), "http://195.127.0.11/uploads/%20%20%20%20/.verify/.eBaysecure=updateuserdataxplimnbqmn-xplmvalidateinfoswqpcmlx=hgplmcx/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host%23.com/%257Ea%2521b%2540c%2523d%2524e%25f%255E00%252611%252A22%252833%252944_55%252B"), 'http://host%23.com/~a!b@c%23d$e%25f^00&11*22(33)44_55+');
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://3279880203/blah"), "http://195.127.0.11/blah");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com/blah/.."), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("www.google.com/"), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("www.google.com"), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.evil.com/blah#frag"), "http://www.evil.com/blah");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.GOOgle.com/"), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com.../"), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com/foo\tbar\rbaz\n2"), "http://www.google.com/foobarbaz2");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com/q?"), "http://www.google.com/q?");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com/q?r?"), "http://www.google.com/q?r?");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.google.com/q?r?s"), "http://www.google.com/q?r?s");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://evil.com/foo#bar#baz"), "http://evil.com/foo");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://evil.com/foo;"), "http://evil.com/foo;");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://evil.com/foo?bar;"), "http://evil.com/foo?bar;");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://€.com/"), "http://%01%80.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://notrailingslash.com"), "http://notrailingslash.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://www.gotaport.com:1234/"), "http://www.gotaport.com:1234/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("  http://www.google.com/  "), "http://www.google.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http:// leadingspace.com/"), "http://%20leadingspace.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://%20leadingspace.com/"), "http://%20leadingspace.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("%20leadingspace.com/"), "http://%20leadingspace.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("https://www.securesite.com/"), "https://www.securesite.com/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host.com/ab%23cd"), "http://host.com/ab%23cd");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host.com//twoslashes?more//slashes"), "http://host.com/twoslashes?more//slashes");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host.com/foo/"), "http://host.com/foo/");
     $this->assertEquals(GSB_UrlUtil::getCanonicalizedUrl("http://host.com/foo?"), "http://host.com/foo?");
     $this->assertEquals("http://host.com/", GSB_UrlUtil::getCanonicalizedUrl("http://host.com:"));
     $this->assertEquals("http://host.com/", GSB_UrlUtil::getCanonicalizedUrl("http://host.com:80"));
     $this->assertEquals("http://host.com/", GSB_UrlUtil::getCanonicalizedUrl("http://host.com:80/"));
     $this->assertEquals("https://host.com/", GSB_UrlUtil::getCanonicalizedUrl("https://host.com:443/"));
     /*
     $url = 'http://host.com/foo%3Fbar';
     $expected = array(
         'canonical' => $url,
         'original'=> $url,
         'host' => 'host.com',
         'path' => '/foo',
         'query' => 'bar',
         'is_ip' => FALSE
     );
     $this->assertEquals($expected, GSB_UrlUtil::canonicalize($url));
     */
 }
Example #2
0
 /**
  * Organizes an array of host keys to a map which is indexed by the host_key
  * value.
  *
  * NOTE: this function is made non-private so we can unit test it.
  *
  * @param array[int]array $urls
  * @return array[string]array
  */
 function hostkeysToHostKeyMap($urls)
 {
     $map = array();
     foreach ((array) $urls as $url) {
         // first canonicalize the URLs
         $canurl = GSB_UrlUtil::canonicalize($url);
         $phashes = GSB_UrlUtil::makePrefixesHashes($canurl['host'], $canurl['path'], $canurl['query'], $canurl['is_ip']);
         // make hostkeys
         $hostkeys = GSB_UrlUtil::makeHostKeyList($canurl['host'], $canurl['is_ip']);
         foreach ((array) $hostkeys as $hostkey) {
             $hostkey['url'] = $url;
             $hostkey['phashes'] = $phashes;
             $map[$hostkey['host_key']] = $hostkey;
         }
     }
     return $map;
 }