urlapi: remove redundant condition in dedotdotify

Bonus: remove two variables, clear up some comments.

Poined out by CodeSonar

Closes #21065
This commit is contained in:
Daniel Stenberg 2026-03-22 23:53:35 +01:00
parent 9820e5dfac
commit 0c475b5df7
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -731,31 +731,25 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
curlx_dyn_init(&out, clen + 1);
/* A. If the input buffer begins with a prefix of "../" or "./", then
remove that prefix from the input buffer; otherwise, */
/* if the input buffer begins with a prefix of "../" or "./", then remove
that prefix from the input buffer; otherwise, */
if(is_dot(&dinput, &dlen)) {
const char *p = dinput;
size_t blen = dlen;
if(!clen)
/* . [end] */
goto end;
else if(ISSLASH(*p)) {
if(ISSLASH(*dinput)) {
/* one dot followed by a slash */
input = p + 1;
input = dinput + 1;
clen = dlen - 1;
}
/* D. if the input buffer consists only of "." or "..", then remove
that from the input buffer; otherwise, */
else if(is_dot(&p, &blen)) {
if(!blen)
/* if the input buffer consists only of "." or "..", then remove
that from the input buffer; otherwise, */
else if(is_dot(&dinput, &dlen)) {
if(!dlen)
/* .. [end] */
goto end;
else if(ISSLASH(*p)) {
else if(ISSLASH(*dinput)) {
/* ../ */
input = p + 1;
clen = blen - 1;
input = dinput + 1;
clen = dlen - 1;
}
}
}
@ -764,9 +758,9 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
if(ISSLASH(*input)) {
const char *p = &input[1];
size_t blen = clen - 1;
/* B. if the input buffer begins with a prefix of "/./" or "/.", where
"." is a complete path segment, then replace that prefix with "/" in
the input buffer; otherwise, */
/* if the input buffer begins with a prefix of "/./" or "/.", where "."
is a complete path segment, then replace that prefix with "/" in the
input buffer; otherwise, */
if(is_dot(&p, &blen)) {
if(!blen) { /* /. */
result = curlx_dyn_addn(&out, "/", 1);
@ -778,10 +772,10 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
continue;
}
/* C. if the input buffer begins with a prefix of "/../" or "/..",
where ".." is a complete path segment, then replace that prefix
with "/" in the input buffer and remove the last segment and its
preceding "/" (if any) from the output buffer; otherwise, */
/* if the input buffer begins with a prefix of "/../" or "/..", where
".." is a complete path segment, then replace that prefix with "/"
in the input buffer and remove the last segment and its preceding
"/" (if any) from the output buffer; otherwise, */
else if(is_dot(&p, &blen) && (ISSLASH(*p) || !blen)) {
/* remove the last segment from the output buffer */
size_t len = curlx_dyn_len(&out);
@ -804,10 +798,10 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
}
}
/* E. move the first path segment in the input buffer to the end of
the output buffer, including the initial "/" character (if any) and
any subsequent characters up to, but not including, the next "/"
character or the end of the input buffer. */
/* move the first path segment in the input buffer to the end of the
output buffer, including the initial "/" character (if any) and any
subsequent characters up to, but not including, the next "/" character
or the end of the input buffer. */
result = curlx_dyn_addn(&out, input, 1);
input++;