diff --git a/src/get_handler.c b/src/get_handler.c index 77e08d9..2cf4120 100644 --- a/src/get_handler.c +++ b/src/get_handler.c @@ -1,6 +1,7 @@ static enum MHD_Result handle_get(struct MHD_Connection *connection, SV url, Settings settings, SV username) { noh_arena_save(&temp); Noh_String fs_path = build_path(false, false, &settings.base_path, &username, &url); + noh_string_replace(&fs_path, '+', ' '); noh_log(NOH_INFO, "Physical path: "Nsv_Fmt, Nsv_Arg(fs_path)); diff --git a/src/noh.h b/src/noh.h index bd98f9e..0a25791 100644 --- a/src/noh.h +++ b/src/noh.h @@ -337,6 +337,9 @@ void noh_string_append_cstr(Noh_String *string, const char *cstr); // Appends null into a Noh_String. void noh_string_append_null(Noh_String *string); +// Replace all occurrences of one character with another in a Noh_String. +void noh_string_replace(Noh_String *string, const char from, const char to); + // Frees a Noh_String, freeing the memory used and settings the count and capacity to 0. #define noh_string_free(string) noh_da_free(string) @@ -847,6 +850,22 @@ void noh_string_append_null(Noh_String *string) { noh_da_append(string, '\0'); } +void noh_string_replace(Noh_String *string, const char from, const char to) { + Noh_String result = {0}; + for (size_t i = 0; i < string->count; i++) { + if (string->elems[i] == from) { + noh_da_append(&result, to); + } else { + noh_da_append(&result, string->elems[i]); + } + } + + noh_string_free(string); + string->elems = result.elems; + string->count = result.count; + string->capacity = result.capacity; +} + bool noh_file_exists(const char *filename) { struct stat st; return (stat(filename, &st)) == 0; diff --git a/src/opds_handler.c b/src/opds_handler.c index 30ba040..52a666e 100644 --- a/src/opds_handler.c +++ b/src/opds_handler.c @@ -49,6 +49,7 @@ static Noh_String create_feed_response(Library_Entry self_path, SV url, Library_ static enum MHD_Result handle_opds(struct MHD_Connection *connection, SV url, Settings settings, SV username) { noh_arena_save(&temp); Noh_String fs_path = build_path(false, false, &settings.base_path, &username, &url); + noh_string_replace(&fs_path, '+', ' '); Noh_String fs_path_cstr = fs_path; noh_string_append_null(&fs_path_cstr); diff --git a/src/path.c b/src/path.c index 431c514..3651043 100644 --- a/src/path.c +++ b/src/path.c @@ -23,5 +23,7 @@ static Noh_String build_path_(bool url, bool go_up, Noh_String_View *first, ...) } va_end(args); + if (url) noh_string_replace(&result, ' ', '+'); + return result; }