Simple url encoding for spaces

This commit is contained in:
2026-06-17 17:34:07 +02:00
parent 9e09114264
commit 1be63ce749
4 changed files with 23 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
static enum MHD_Result handle_get(struct MHD_Connection *connection, SV url, Settings settings, SV username) { static enum MHD_Result handle_get(struct MHD_Connection *connection, SV url, Settings settings, SV username) {
noh_arena_save(&temp); noh_arena_save(&temp);
Noh_String fs_path = build_path(false, false, &settings.base_path, &username, &url); 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)); noh_log(NOH_INFO, "Physical path: "Nsv_Fmt, Nsv_Arg(fs_path));

View File

@@ -337,6 +337,9 @@ void noh_string_append_cstr(Noh_String *string, const char *cstr);
// Appends null into a Noh_String. // Appends null into a Noh_String.
void noh_string_append_null(Noh_String *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. // 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) #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'); 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) { bool noh_file_exists(const char *filename) {
struct stat st; struct stat st;
return (stat(filename, &st)) == 0; return (stat(filename, &st)) == 0;

View File

@@ -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) { static enum MHD_Result handle_opds(struct MHD_Connection *connection, SV url, Settings settings, SV username) {
noh_arena_save(&temp); noh_arena_save(&temp);
Noh_String fs_path = build_path(false, false, &settings.base_path, &username, &url); 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 fs_path_cstr = fs_path;
noh_string_append_null(&fs_path_cstr); noh_string_append_null(&fs_path_cstr);

View File

@@ -23,5 +23,7 @@ static Noh_String build_path_(bool url, bool go_up, Noh_String_View *first, ...)
} }
va_end(args); va_end(args);
if (url) noh_string_replace(&result, ' ', '+');
return result; return result;
} }