Changeset 20533 for lang/php

Show
Ignore:
Timestamp:
10/02/08 23:45:03 (2 months ago)
Author:
sasezaki
Message:

modify getAbsoulteUrl() etc.

Location:
lang/php/Scraper
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/php/Scraper/library/Diggin/Scraper/Strategy/Flexible.php

    r20204 r20533  
    100100    protected static function _xpathOrCss2Xpath($exp){ 
    101101        if (preg_match('!^(?:/|id\()!', $exp)) { 
    102             return $exp; 
     102            return '.'.$exp; 
    103103        } else { 
    104104            if ($exp === '.') { 
  • lang/php/Scraper/library/Diggin/Uri/Http.php

    r20204 r20533  
    1515 */ 
    1616 
     17/** 
     18 * Utils For Http 
     19 */ 
    1720class Diggin_Uri_Http 
    1821{ 
     
    3538            } else { 
    3639                if (strpos(pathinfo(parse_url($base_url, PHP_URL_PATH), PATHINFO_DIRNAME), '/') === false) { 
    37                     return http_build_url($base_url, array("path" => $url,), 
     40                    return http_build_url($base_url, array("path" => $url), 
    3841                    HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT); 
    3942                } else {             
    40                     return http_build_url($base_url, array("path" => $url,),  
     43                    return http_build_url($base_url, array("path" => $url),  
    4144                    HTTP_URL_JOIN_PATH | HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT); 
    4245                } 
     
    4447        //Net_URL2 ver 0.2.0 
    4548        } else { 
    46             if (!class_exists('Net_URL2')) require_once 'Net/URL2.php'; 
     49                        if (!class_exists('Net_URL2')) require_once 'Net/URL2.php'; 
     50                        static $neturl2; 
    4751            $neturl2 = new Net_URL2($base_url); 
    48             return $neturl2->resolve($url)->getUrl(); 
    49         } 
     52            return $neturl2->resolve(str_replace(chr(32), '%20', $url))->getUrl(); 
     53        }  
    5054    } 
    5155} 
  • lang/php/Scraper/tests/Diggin/Uri/HttpTest.php

    r20321 r20533  
    4040     * check getting absoluteUrl 
    4141     * 
    42      * 
    43      * import from rhaco's doc-test 
    44      * @see http://rhaco.googlecode.com/svn/trunk/1_6_1/network/Url.php 
    4542     */ 
    4643    public function testGetAbsoluteUrl() 
    4744    { 
     45        //if  
     46        $this->assertEquals('http://yahoo.com/test/',  
     47                             $this->object->getAbsoluteUrl('http://yahoo.com/test/', 'http://www.rhaco.org/')); 
     48         
     49        // import from rhaco's doc-test 
     50        // @see http://rhaco.googlecode.com/svn/trunk/1_6_1/network/Url.php 
    4851        $this->assertEquals('http://www.rhaco.org/doc/ja/index.html',  
    4952                             $this->object->getAbsoluteUrl('/doc/ja/index.html', 'http://www.rhaco.org/')); 
     
    7073        $this->assertEquals('http://www.rhaco.org/index.html',  
    7174                             $this->object->getAbsoluteUrl('/index.html', 'http://www.rhaco.org/doc/ja')); 
     75                              
     76                //@see http://d.hatena.ne.jp/kitamomonga/20080410/ruby_mechanize_percent_url_bug 
     77        $this->assertEquals('http://test.org/doc/ja/index.cgi?param=hoge',  
     78                             $this->object->getAbsoluteUrl('?param=hoge', 'http://test.org/doc/ja/index.cgi?test=bar')); 
     79        $this->assertEquals('http://test.org/index.php?param=hoge',  
     80                             $this->object->getAbsoluteUrl('?param=hoge', 'http://test.org/index.php'));                 
     81        //if space, 
     82        $this->assertEquals('http://www.rhaco.org/doc/ja/'.rawurlencode('test space.html'), 
     83                             $this->object->getAbsoluteUrl('test space.html', 'http://www.rhaco.org/doc/ja/')); 
     84         
    7285    } 
    7386}