From 2e217aee6dd77481f5957c21ed6d3cbac99df4ca Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 10 Mar 2023 09:47:43 -0600 Subject: [PATCH] Fixed bug relating to DEFAULT_PATH in url_to_path function --- url_manipulation.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/url_manipulation.c b/url_manipulation.c index be58483..f62cb9a 100644 --- a/url_manipulation.c +++ b/url_manipulation.c @@ -2,7 +2,7 @@ #include #include -#define DEFAULT_PATH "/index.html" +#define DEFAULT_PATH "/" char* url_to_proto(char* url) { size_t length = strlen(url); @@ -68,8 +68,12 @@ char* url_to_path(char* url) { } } - if (sentinel == 0) { - to_return = DEFAULT_PATH; + if (num_slashes < 3 || sentinel == str_len) { /* If we don't find the requisite number of slashes after + parsing the string OR the third slash is at the end of the string + ("e.g. www.example.com/")... */ + + strcpy(to_return,DEFAULT_PATH); /* ...Then return the default path - "/" */ + return to_return; } /* Copy all bytes of the string, starting from the third slash */