src/lib/url/url_canon_relative.cc
// A subroutine of DoResolveRelativeURL, this resolves the URL knowning that
// the input is a relative path or less (qyuery or ref).
A subroutine of DoResolveRelativeURL, this resolves the URL knowning that
the input is a relative path or less (qyuery or ref).
A subroutine of DoResolveRelativeURL this resolves the URL knowning that the input is a relative path or less ( qyuery or ref ) .
bool DoResolveRelativePath(const char* base_url, const Parsed& base_parsed, bool base_is_file,
                           const char* relative_url, const Component& relative_component,
                           CharsetConverter* query_converter, CanonOutput* output,
                           Parsed* out_parsed) {
  bool success = true;
  Component path, query, ref;
  ParsePathInternal(relative_url, relative_component, &path, &query, &ref);
  output->Append(base_url, base_parsed.path.begin);
  if (path.is_nonempty()) {
    int true_path_begin = output->length();
    int base_path_begin = base_parsed.path.begin;
    if (IsURLSlash(relative_url[path.begin])) {
      success &= CanonicalizePath(relative_url, path, output, &out_parsed->path);
    } else {
      int path_begin = output->length();
      CopyToLastSlash(base_url, base_path_begin, base_parsed.path.end(), output);
      success &= CanonicalizePartialPath(relative_url, path, path_begin, output);
      out_parsed->path = MakeRange(path_begin, output->length());
    }
    CanonicalizeQuery(relative_url, query, query_converter, output, &out_parsed->query);
    CanonicalizeRef(relative_url, ref, output, &out_parsed->ref);
    out_parsed->path = MakeRange(true_path_begin, out_parsed->path.end());
    return success;
  }
  CopyOneComponent(base_url, base_parsed.path, output, &out_parsed->path);
  if (query.is_valid()) {
    CanonicalizeQuery(relative_url, query, query_converter, output, &out_parsed->query);
    CanonicalizeRef(relative_url, ref, output, &out_parsed->ref);
    return success;
  }
  if (base_parsed.query.is_valid())
    output->push_back('?');
  CopyOneComponent(base_url, base_parsed.query, output, &out_parsed->query);
  if (ref.is_valid()) {
    CanonicalizeRef(relative_url, ref, output, &out_parsed->ref);
    return success;
  }
  FX_DCHECK(false) << "Not reached";
  return success;
}
bool DoResolveRelativePath ( const char * base_url , const Parsed & base_parsed , bool base_is_file , const char * relative_url , const Component & relative_component , CharsetConverter * query_converter , CanonOutput * output , Parsed * out_parsed ) { bool success = true ; Component path , query , ref ; ParsePathInternal ( relative_url , relative_component , & path , & query , & ref ) ; output -> Append ( base_url , base_parsed . path . begin ) ; if ( path . is_nonempty ( ) ) { int true_path_begin = output -> length ( ) ; int base_path_begin = base_parsed . path . begin ; if ( IsURLSlash ( relative_url [ path . begin ] ) ) { success &= CanonicalizePath ( relative_url , path , output , & out_parsed -> path ) ; } else { int path_begin = output -> length ( ) ; CopyToLastSlash ( base_url , base_path_begin , base_parsed . path . end ( ) , output ) ; success &= CanonicalizePartialPath ( relative_url , path , path_begin , output ) ; out_parsed -> path = MakeRange ( path_begin , output -> length ( ) ) ; } CanonicalizeQuery ( relative_url , query , query_converter , output , & out_parsed -> query ) ; CanonicalizeRef ( relative_url , ref , output , & out_parsed -> ref ) ; out_parsed -> path = MakeRange ( true_path_begin , out_parsed -> path . end ( ) ) ; return success ; } CopyOneComponent ( base_url , base_parsed . path , output , & out_parsed -> path ) ; if ( query . is_valid ( ) ) { CanonicalizeQuery ( relative_url , query , query_converter , output , & out_parsed -> query ) ; CanonicalizeRef ( relative_url , ref , output , & out_parsed -> ref ) ; return success ; } if ( base_parsed . query . is_valid ( ) ) output -> push_back ( ' ' ) ; CopyOneComponent ( base_url , base_parsed . query , output , & out_parsed -> query ) ; if ( ref . is_valid ( ) ) { CanonicalizeRef ( relative_url , ref , output , & out_parsed -> ref ) ; return success ; } FX_DCHECK ( false ) << " " ; return success ; }
A subroutine of DoResolveRelativeURL, this resolves the URL knowning that
the input is a relative path or less (qyuery or ref).
A subroutine of DoResolveRelativeURL this resolves the URL knowning that the input is a relative path or less ( qyuery or ref ) .
// We know the authority section didn't change, copy it to the output. We // also know we have a path so can copy up to there. // Canonical URLs always have a path, so we can use that offset. // The path is replaced or modified. // Easy case: the path is an absolute path on the server, so we can // just replace everything from the path on with the new versions. // Since the input should be canonical hierarchical URL, we should // always have a path. // Relative path, replace the query, and reference. We take the // original path with the file part stripped, and append the new path. // The canonicalizer will take care of resolving ".." and "." // Copy the rest of the stuff after the path from the relative path. // Finish with the query and reference part (these can't fail). // Fix the path beginning to add back the "C:" we may have written above. // If we get here, the path is unchanged: copy to output. // Just the query specified, replace the query and reference (ignore // failures for refs) // If we get here, the query is unchanged: copy to output. Note that the // range of the query parameter doesn't include the question mark, so we // have to add it manually if there is a component. // Just the reference specified: replace it (ignoring failures). // We should always have something to do in this function, the caller checks // that some component is being replaced.