зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1621088 - Convert functions net_ResolveRelativePath to rust.r=valentin
Differential Revision: https://phabricator.services.mozilla.com/D68981 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8390d2e8bc
Коммит
ea74e90682
|
@ -346,70 +346,6 @@ void net_CoalesceDirs(netCoalesceFlags flags, char* path) {
|
||||||
*urlPtr = '\0'; // terminate the url
|
*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
|
// scheme fu
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -60,23 +60,6 @@ nsresult net_ParseFileURL(const nsACString& inURL, nsACString& outDirectory,
|
||||||
/* handle .. in dirs while resolving URLs (path is UTF-8) */
|
/* handle .. in dirs while resolving URLs (path is UTF-8) */
|
||||||
void net_CoalesceDirs(netCoalesceFlags flags, char* path);
|
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
|
* Check if a URL is absolute
|
||||||
*
|
*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче