#38 <base> tag not checked at fetching links

open
nobody
None
5
2005-01-06
2005-01-06
Anonymous
No

When fetching links snoopy doesn't check, if <base>
html tag is set so it returns incorrect links in this case.

Discussion

  • Logged In: NO

    HA! Corrected this bug too.

    Solution:

    First add a new variable under "private variables":
    var $_baseurl = "";

    then in _httprequest and _httpsrequest functions add this
    piece of code just above the "// have we hit our frame depth
    and is there frame src to fetch?" comment line:
    // check if there is a base tag
    if(preg_match("'<base[\s]*href[\s]*=[\"\']?([^\'\"\&gt;]
    +)'i",$results,$match))
    $this->_baseurl = $match[1];
    else
    $this->_baseurl = "";

    then in fetchlinks function replace this code:
    if($this->expandlinks)
    $this->results = $this->_expandlinks($this->results, $URI);

    with this code:
    if($this->expandlinks)
    if($this->_baseurl)
    $this->results = $this->_expandlinks($this->results, $this-
    >_baseurl);
    elseif($this->lastredirectaddr)
    $this->results = $this->_expandlinks($this->results, $this-
    >lastredirectaddr);
    else
    $this->results = $this->_expandlinks($this->results, $URI);

    that's it.

    this comment form is not very good for pasting code as it
    breaks it, but I am sure you will be able to put broken lines
    back together fine when copying the code.

    now someone add this to the next snoopy update!

    -- McSpike --