Fix broken path parsing

FossilOrigin-Name: 5040e8d660047072b4b829e4da564e744b8c44c0233ef85ee5a6c7c82e1a2918
This commit is contained in:
me@ow.nekobit.net 2022-02-24 02:58:47 +00:00
parent 041868d214
commit 81c12a35e6
2 changed files with 14 additions and 7 deletions

View file

@ -28,7 +28,7 @@ enum path_state
PARSE_READ,
};
void parse_path(mastodont_t* api, struct path_info* path_info)
int parse_path(mastodont_t* api, struct path_info* path_info)
{
int fail = 0, fin = 0;
enum path_state state = PARSE_NEUTRAL;
@ -77,13 +77,18 @@ void parse_path(mastodont_t* api, struct path_info* path_info)
}
else {
// Don't realloc, we already have a space for our final character
if (p2[i] == '\0')
if (p2[i] == '\0' || p2[i] == '/')
{
tmp[str_size] = '\0';
++j;
// Move --i back one to counter the upcoming ++i
// If we don't, then we are one step too far
--i;
}
else {
tmp = realloc(tmp, ++str_size + 1);
tmp[str_size-1] = p2[i];
}
tmp = realloc(tmp, ++str_size + 1);
tmp[str_size-1] = p2[i];
}
@ -95,7 +100,7 @@ void parse_path(mastodont_t* api, struct path_info* path_info)
}
breakpt:
if (fail)
return;
return 1;
path_info->callback(api, data, size);
@ -105,6 +110,7 @@ breakpt:
free(data[i]);
}
if (data) free(data);
return 0;
}
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len)
@ -118,7 +124,8 @@ void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len)
else { // Generic path
for (size_t i = 0; i < paths_len; ++i)
{
parse_path(api, paths + i);
if (parse_path(api, paths + i) == 0)
return;
}
}
}

View file

@ -28,6 +28,6 @@ struct path_info
};
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len);
void parse_path(mastodont_t* api, struct path_info* path_info);
int parse_path(mastodont_t* api, struct path_info* path_info);
#endif // PATH_H