Mercurial
comparison hg-web/main.c @ 188:32ce881452fa hg-web
Fixing few stuff.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 22:50:28 -0800 |
| parents | 71ad34a8bc9a |
| children | a2725419f988 |
comparison
equal
deleted
inserted
replaced
| 187:a69485d9f2e1 | 188:32ce881452fa |
|---|---|
| 17 | 17 |
| 18 static char* sanitize_path(const char *input_path, Dowa_Arena *arena) | 18 static char* sanitize_path(const char *input_path, Dowa_Arena *arena) |
| 19 { | 19 { |
| 20 if (!input_path || strlen(input_path) == 0) | 20 if (!input_path || strlen(input_path) == 0) |
| 21 { | 21 { |
| 22 char *empty = Dowa_Arena_Allocate(arena, 1); | 22 char *empty = Dowa_Arena_Allocate(arena, 1); |
| 23 empty[0] = '\0'; | 23 empty[0] = '\0'; |
| 24 return empty; | 24 return empty; |
| 25 } | 25 } |
| 26 | 26 |
| 27 size_t len = strlen(input_path); | 27 size_t len = strlen(input_path); |
| 28 char *result = Dowa_Arena_Allocate(arena, len + 1); | 28 char *result = Dowa_Arena_Allocate(arena, len + 1); |
| 29 size_t j = 0; | 29 size_t j = 0; |
| 30 | 30 |
| 31 for (size_t i = 0; i < len; i++) | 31 for (size_t i = 0; i < len; i++) |
| 32 { | 32 { |
| 33 if (input_path[i] == '.' && (i == 0 || input_path[i-1] == '/')) { | 33 if (input_path[i] == '.' && (i == 0 || input_path[i-1] == '/')) |
| 34 if (i + 1 < len && input_path[i+1] == '.') { | 34 { |
| 35 // Skip ".." | 35 if (i + 1 < len && input_path[i+1] == '.') |
| 36 i++; | 36 { |
| 37 continue; | 37 // Skip ".." |
| 38 i++; | |
| 39 continue; | |
| 38 } | 40 } |
| 39 // Skip "." | 41 // Skip "." |
| 40 continue; | 42 continue; |
| 41 } | 43 } |
| 42 result[j++] = input_path[i]; | 44 result[j++] = input_path[i]; |
| 43 } | 45 } |
| 44 result[j] = '\0'; | 46 result[j] = '\0'; |
| 45 | 47 |
| 46 // Remove leading/trailing slashes | 48 // Remove leading/trailing slashes |
| 47 while (result[0] == '/') | 49 while (result[0] == '/') |
| 48 memmove(result, result + 1, strlen(result)); | 50 memmove(result, result + 1, strlen(result)); |
| 49 while (j > 0 && result[j-1] == '/') | 51 while (j > 0 && result[j-1] == '/') |
| 50 result[--j] = '\0'; | 52 result[--j] = '\0'; |
| 51 | 53 |
| 52 return result; | 54 return result; |
| 53 } | 55 } |
| 54 | 56 |
| 55 Seobeo_Client_Response *hg_proxy_request( | 57 Seobeo_Client_Response *hg_proxy_request( |