From ed93a133dff2ef55717e7b1a02a46f697be20c7c Mon Sep 17 00:00:00 2001 From: Jonathan Kamens Date: Fri, 29 Sep 2023 14:32:31 -0400 Subject: [PATCH] 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. --- src/link.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/link.c b/src/link.c index c7b919d..a9749a3 100644 --- a/src/link.c +++ b/src/link.c @@ -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. */