return buf;
}
+ // Check if path has "0x2F" inside of it to determine if delimeters will be
+ // "0x2F" or "%2F".
+ uint_fast8_t is_normal_delimeter = 1;
+ const size_t path_len = strlen(stripped_path);
+ for (size_t idx = 0; stripped_path[idx] != 0; ++idx) {
+ if (idx + 4 <= path_len && strncmp(stripped_path + idx, "0x2F", 4) == 0) {
+ is_normal_delimeter = 0;
+ break;
+ }
+ }
+
+ // Create the cache-filename piece by piece.
__attribute__((cleanup(simple_archiver_list_free)))
SDArchiverLinkedList *parts = simple_archiver_list_init();
size_t idx = 0;
size_t prev_idx = 0;
- const size_t path_len = strlen(stripped_path);
size_t size;
for (; idx < path_len && stripped_path[idx] != 0; ++idx) {
c_simple_http_add_string_part(parts, temp_buf, 0);
free(temp_buf);
- temp_buf = malloc(5);
- memcpy(temp_buf, "0x2F", 5);
- c_simple_http_add_string_part(parts, temp_buf, 0);
- free(temp_buf);
+ if (is_normal_delimeter) {
+ temp_buf = malloc(5);
+ memcpy(temp_buf, "0x2F", 5);
+ c_simple_http_add_string_part(parts, temp_buf, 0);
+ free(temp_buf);
+ } else {
+ temp_buf = malloc(4);
+ memcpy(temp_buf, "%2F", 4);
+ c_simple_http_add_string_part(parts, temp_buf, 0);
+ free(temp_buf);
+ }
prev_idx = idx + 1;
}
ret = c_simple_http_path_to_cache_filename("/outer///inner");
CHECK_TRUE(strcmp(ret, "0x2Fouter0x2Finner") == 0);
free(ret);
+
+ ret = c_simple_http_path_to_cache_filename("/outer/with_hex_0x2F_inner");
+ CHECK_TRUE(strcmp(ret, "%2Fouter%2Fwith_hex_0x2F_inner") == 0);
+ free(ret);
+
+ ret = c_simple_http_path_to_cache_filename("/outer/0x2F_hex_inner");
+ CHECK_TRUE(strcmp(ret, "%2Fouter%2F0x2F_hex_inner") == 0);
+ free(ret);
+
+ ret = c_simple_http_path_to_cache_filename("/outer0x2F/inner_hex_0x2F");
+ CHECK_TRUE(strcmp(ret, "%2Fouter0x2F%2Finner_hex_0x2F") == 0);
+ free(ret);
+
+ ret = c_simple_http_path_to_cache_filename(
+ "/0x2Fouter0x2F/0x2Finner_0x2F_hex_0x2F");
+ CHECK_TRUE(strcmp(ret, "%2F0x2Fouter0x2F%2F0x2Finner_0x2F_hex_0x2F") == 0);
+ free(ret);
}
RETURN()