Fix minor logic bug and code smell in make_link_relative

Don't assume that the reason why we didn't find enough slashes in a
URL is because the user didn't specify the slash at the end of the
host name, unless we did find the first two slashes.

Add some curly braces around an if block to make it clear to people
and the compiler which statement an `else` applies to. The logic was
correct before but the indentation was wrong, making it especially
confusing.
This commit is contained in:
Jonathan Kamens 2023-09-29 14:32:31 -04:00 committed by Fufu Fang
parent 7bcd43068d
commit ed93a133df
1 changed files with 4 additions and 3 deletions

View File

@ -1131,15 +1131,16 @@ static void make_link_relative(const char *page_url, char *link_url)
when we're done we want the pointer to point at the final slash. */
page_url++;
}
if (slashes_left_to_find)
if (! *page_url)
if (slashes_left_to_find) {
if (slashes_left_to_find == 1 && ! *page_url)
/* We're at the top level of the web site and the user entered the URL
without a trailing slash. */
page_url = "/";
else
else
/* Well, that's odd. Let's return rather than trying to dig ourselves
deeper into whatever hole we're in. */
return;
}
/* The page URL is no longer the full page_url, it's just the part after
the host name. */
/* The link URL should start with the page URL. */