Simple url encoding for spaces
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
19
src/noh.h
19
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user