Bug 1621088 - Convert functions net_ResolveRelativePath to rust.r=valentin
authorMahakBansal <mbansal@cs.iitr.ac.in>
Fri, 03 Apr 2020 10:49:49 +0000
changeset 521995 976858118c046b6b2bf26031f99393bcb98900ea
parent 521994 b9ebe58001d787bb0bbad6d39ae8681966d5a77f
child 521996 d06d14647f6fe993990383a12b185a3a54bf4872
push id37281
push userbtara@mozilla.com
push dateSat, 04 Apr 2020 09:29:13 +0000
treeherdermozilla-central@26bcd52f3e76 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1621088
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1621088 - Convert functions net_ResolveRelativePath to rust.r=valentin Differential Revision: https://phabricator.services.mozilla.com/D68981
netwerk/base/nsURLHelper.cpp
netwerk/base/nsURLHelper.h
--- a/netwerk/base/nsURLHelper.cpp
+++ b/netwerk/base/nsURLHelper.cpp
@@ -341,80 +341,16 @@ void net_CoalesceDirs(netCoalesceFlags f
 
   // Copy remaining stuff past the #?;
   for (; *fwdPtr != '\0'; ++fwdPtr) {
     *urlPtr++ = *fwdPtr;
   }
   *urlPtr = '\0';  // terminate the url
 }
 
-nsresult net_ResolveRelativePath(const nsACString& relativePath,
-                                 const nsACString& basePath,
-                                 nsACString& result) {
-  nsAutoCString name;
-  nsAutoCString path(basePath);
-  bool needsDelim = false;
-
-  if (!path.IsEmpty()) {
-    char16_t last = path.Last();
-    needsDelim = !(last == '/');
-  }
-
-  nsACString::const_iterator beg, end;
-  relativePath.BeginReading(beg);
-  relativePath.EndReading(end);
-
-  bool stop = false;
-  char c;
-  for (; !stop; ++beg) {
-    c = (beg == end) ? '\0' : *beg;
-    // printf("%c [name=%s] [path=%s]\n", c, name.get(), path.get());
-    switch (c) {
-      case '\0':
-      case '#':
-      case '?':
-        stop = true;
-        [[fallthrough]];
-      case '/':
-        // delimiter found
-        if (name.EqualsLiteral("..")) {
-          // pop path
-          // If we already have the delim at end, then
-          //  skip over that when searching for next one to the left
-          int32_t offset = path.Length() - (needsDelim ? 1 : 2);
-          // First check for errors
-          if (offset < 0) return NS_ERROR_MALFORMED_URI;
-          int32_t pos = path.RFind("/", false, offset);
-          if (pos >= 0)
-            path.Truncate(pos + 1);
-          else
-            path.Truncate();
-        } else if (name.IsEmpty() || name.EqualsLiteral(".")) {
-          // do nothing
-        } else {
-          // append name to path
-          if (needsDelim) path += '/';
-          path += name;
-          needsDelim = true;
-        }
-        name.Truncate();
-        break;
-
-      default:
-        // append char to name
-        name += c;
-    }
-  }
-  // append anything left on relativePath (e.g. #..., ;..., ?...)
-  if (c != '\0') path += Substring(--beg, end);
-
-  result = path;
-  return NS_OK;
-}
-
 //----------------------------------------------------------------------------
 // scheme fu
 //----------------------------------------------------------------------------
 
 static bool net_IsValidSchemeChar(const char aChar) {
   return mozilla::net::rust_net_is_valid_scheme_char(aChar);
 }
 
--- a/netwerk/base/nsURLHelper.h
+++ b/netwerk/base/nsURLHelper.h
@@ -56,33 +56,16 @@ nsresult net_GetFileFromURLSpec(const ns
 nsresult net_ParseFileURL(const nsACString& inURL, nsACString& outDirectory,
                           nsACString& outFileBaseName,
                           nsACString& outFileExtension);
 
 /* handle .. in dirs while resolving URLs (path is UTF-8) */
 void net_CoalesceDirs(netCoalesceFlags flags, char* path);
 
 /**
- * Resolves a relative path string containing "." and ".."
- * with respect to a base path (assumed to already be resolved).
- * For example, resolving "../../foo/./bar/../baz.html" w.r.t.
- * "/a/b/c/d/e/" yields "/a/b/c/foo/baz.html". Attempting to
- * ascend above the base results in the NS_ERROR_MALFORMED_URI
- * exception. If basePath is null, it treats it as "/".
- *
- * @param relativePath  a relative URI
- * @param basePath      a base URI
- *
- * @return a new string, representing canonical uri
- */
-nsresult net_ResolveRelativePath(const nsACString& relativePath,
-                                 const nsACString& basePath,
-                                 nsACString& result);
-
-/**
  * Check if a URL is absolute
  *
  * @param inURL     URL spec
  * @return true if the given spec represents an absolute URL
  */
 bool net_IsAbsoluteURL(const nsACString& inURL);
 
 /**