Skip to content

Commit

Permalink
Fix minor logic bug and code smell in make_link_relative
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jikamens authored and fangfufu committed Sep 29, 2023
1 parent 7bcd430 commit ed93a13
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit ed93a13

Please sign in to comment.