src/lib/url/url_canon_relative.cc
// See IsRelativeURL in the header file for usage.
See IsRelativeURL in the header file for usage.
See IsRelativeURL in the header file for usage .
bool IsRelativeURL(const char* base, const Parsed& base_parsed, const char* url, size_t url_len,
                   bool is_base_hierarchical, bool* is_relative, Component* relative_component) {
  *is_relative = false;  
  size_t begin = 0;
  TrimURL(url, &begin, &url_len);
  if (begin >= url_len) {
    *relative_component = Component(begin, 0);
    *is_relative = true;
    return true;
  }
  Component scheme;
  const bool scheme_is_empty = !ExtractScheme(url, url_len, &scheme) || scheme.len() == 0;
  if (scheme_is_empty) {
    if (url[begin] == '#') {
    } else if (!is_base_hierarchical) {
      return false;
    }
    *relative_component = MakeRange(begin, url_len);
    *is_relative = true;
    return true;
  }
  int scheme_end = scheme.end();
  for (int i = scheme.begin; i < scheme_end; i++) {
    if (!CanonicalSchemeChar(url[i])) {
      if (!is_base_hierarchical) {
        return false;
      }
      *relative_component = MakeRange(begin, url_len);
      *is_relative = true;
      return true;
    }
  }
  if (!AreSchemesEqual(base, base_parsed.scheme, url, scheme))
    return true;
  if (!is_base_hierarchical)
    return true;
  size_t colon_offset = scheme.end();
  size_t num_slashes = CountConsecutiveSlashes(url, colon_offset + 1, url_len);
  if (num_slashes == 0 || num_slashes == 1) {
    *is_relative = true;
    *relative_component = MakeRange(colon_offset + 1, url_len);
    return true;
  }
  return true;
}
bool IsRelativeURL ( const char * base , const Parsed & base_parsed , const char * url , size_t url_len , bool is_base_hierarchical , bool * is_relative , Component * relative_component ) { * is_relative = false ; size_t begin = 0 ; TrimURL ( url , & begin , & url_len ) ; if ( begin >= url_len ) { * relative_component = Component ( begin , 0 ) ; * is_relative = true ; return true ; } Component scheme ; const bool scheme_is_empty = ! ExtractScheme ( url , url_len , & scheme ) || scheme . len ( ) == 0 ; if ( scheme_is_empty ) { if ( url [ begin ] == ' ' ) { } else if ( ! is_base_hierarchical ) { return false ; } * relative_component = MakeRange ( begin , url_len ) ; * is_relative = true ; return true ; } int scheme_end = scheme . end ( ) ; for ( int i = scheme . begin ; i < scheme_end ; i ++ ) { if ( ! CanonicalSchemeChar ( url [ i ] ) ) { if ( ! is_base_hierarchical ) { return false ; } * relative_component = MakeRange ( begin , url_len ) ; * is_relative = true ; return true ; } } if ( ! AreSchemesEqual ( base , base_parsed . scheme , url , scheme ) ) return true ; if ( ! is_base_hierarchical ) return true ; size_t colon_offset = scheme . end ( ) ; size_t num_slashes = CountConsecutiveSlashes ( url , colon_offset + 1 , url_len ) ; if ( num_slashes == 0 || num_slashes == 1 ) { * is_relative = true ; * relative_component = MakeRange ( colon_offset + 1 , url_len ) ; return true ; } return true ; }
See IsRelativeURL in the header file for usage.
See IsRelativeURL in the header file for usage .
// So we can default later to not relative. // Trim whitespace and construct a new range for the substring. // Empty URLs are relative, but do nothing. // See if we've got a scheme, if not, we know this is a relative URL. // BUT, just because we have a scheme, doesn't make it absolute. // "http:foo.html" is a relative URL with path "foo.html". If the scheme is // empty, we treat it as relative (":foo"), like IE does. // |url| is a bare fragment (e.g. "#foo"). This can be resolved against // any base. Fall-through. // Don't allow relative URLs if the base scheme doesn't support it. // If the scheme isn't valid, then it's relative. // Don't allow relative URLs if the base scheme doesn't support it. // If the scheme is not the same, then we can't count it as relative. // When the scheme that they both share is not hierarchical, treat the // incoming scheme as absolute (this way with the base of "data:foo", // "data:bar" will be reported as absolute. // ExtractScheme guarantees that the colon immediately follows what it // considers to be the scheme. CountConsecutiveSlashes will handle the // case where the begin offset is the end of the input. // No slashes means it's a relative path like "http:foo.html". One slash // is an absolute path. "http:/home/foo.html" // Two or more slashes after the scheme we treat as absolute.