pike.git / lib / modules / Standards.pmod / URI.pike

version» Context lines:

pike.git/lib/modules/Standards.pmod/URI.pike:1:   #pike __REAL_VERSION__      //! This class implements URI parsing and resolving of relative references to   //! absolute form, as defined in RFC 2396 and RFC 3986.      // Implemented by Johan Sundström and Johan Schön. - // $Id: URI.pike,v 1.24 2006/07/13 15:35:46 nilsson Exp $ + // $Id: URI.pike,v 1.25 2006/11/04 19:06:49 nilsson Exp $      #pragma strict_types      //! Scheme component of URI   string scheme;      //! Authority component of URI (formerly called net_loc, from RFC 2396   //! known as authority)   string authority;   
pike.git/lib/modules/Standards.pmod/URI.pike:95:   string combine_uri_path(string base, string rel)   {    string buf;       // RFC 2396, §5.2.6:    // a) All but the last segment of the base URI's path component is    // copied to the buffer. In other words, any characters after the    // last (right-most) slash character, if any, are excluded.    array segments=base/"/";    if(has_value(base, "/")) -  buf=segments[..sizeof(segments)-2]*"/"+"/"; +  buf=segments[..<1]*"/"+"/";    else    buf=base;       // b) The reference's path component is appended to the buffer string.    buf+=rel;    segments = buf / "/";       // c) All occurrences of "./", where "." is a complete path segment,    // are removed from the buffer string.    for(int i=0; i<sizeof(segments)-1; i++)    if(segments[i]==".")    segments[i]=0;       segments -= ({ 0 });       // d) If the buffer string ends with "." as a complete path segment,    // that "." is removed.    if(segments[-1]==".") -  segments=segments[..sizeof(segments)-2]+({""}); +  segments=segments[..<1]+({""});       // e) All occurrences of "<segment>/../", where <segment> is a    // complete path segment not equal to "..", are removed from the    // buffer string. Removal of these path segments is performed    // iteratively, removing the leftmost matching pattern on each    // iteration, until no matching pattern remains.    int found_pattern;    do    {    found_pattern=0;
pike.git/lib/modules/Standards.pmod/URI.pike:144:    }    }       } while(found_pattern);       // f) If the buffer string ends with "<segment>/..", where <segment>    // is a complete path segment not equal to "..", that    // "<segment>/.." is removed.    if(sizeof(segments)>=2)    if(segments[-2]!=".." && segments[-1]=="..") -  segments=segments[..sizeof(segments)-3]+({""}); +  segments=segments[..<2]+({""});       // g) If the resulting buffer string still begins with one or more    // complete path segments of "..", then the reference is    // considered to be in error. Implementations may handle this    // error by retaining these components in the resolved path (i.e.,    // treating them as part of the final URI), by removing them from    // the resolved path (i.e., discarding relative levels above the    // root), or by avoiding traversal of the reference.    return segments * "/";   }