mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-28 01:47:18 +01:00
libbbfdm-api: ignore trailing dots in reference paths
This commit is contained in:
parent
efc6f91b55
commit
a707ed46b0
2 changed files with 39 additions and 5 deletions
|
|
@ -291,13 +291,20 @@ int bbfdm_get_reference_linker(struct dmctx *ctx, char *reference_path, struct d
|
|||
{
|
||||
char hash_str[9] = {0};
|
||||
char *uci_val = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!reference_path || !reference_args)
|
||||
return -1;
|
||||
|
||||
// Remove trailing dot if present
|
||||
len = DM_STRLEN(reference_path);
|
||||
if (len > 0 && reference_path[len - 1] == '.') {
|
||||
reference_path[len - 1] = '\0';
|
||||
}
|
||||
|
||||
reference_args->path = reference_path;
|
||||
|
||||
if (DM_STRLEN(reference_args->path) == 0)
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
calculate_hash(reference_path, hash_str, sizeof(hash_str));
|
||||
|
|
|
|||
|
|
@ -896,16 +896,42 @@ static bool is_same_reference_path(const char *curr_value, const char *in_value)
|
|||
char *pch = NULL, *pchr = NULL;
|
||||
char resolved_path[2048] = {0};
|
||||
char buf[2048] = {0};
|
||||
unsigned pos = 0;
|
||||
char cleaned_in_value[2048] = {0};
|
||||
unsigned pos = 0, clean_pos = 0;
|
||||
|
||||
if (!curr_value || !in_value)
|
||||
return false;
|
||||
|
||||
if (strcmp(curr_value, in_value) == 0)
|
||||
DM_STRNCPY(buf, in_value, sizeof(buf));
|
||||
for (pch = strtok_r(buf, ",", &pchr);
|
||||
pch != NULL && clean_pos < sizeof(cleaned_in_value) - 1;
|
||||
pch = strtok_r(NULL, ",", &pchr)) {
|
||||
|
||||
size_t len = strlen(pch);
|
||||
while (len > 0 && pch[len - 1] == '.') {
|
||||
pch[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
int written = snprintf(&cleaned_in_value[clean_pos],
|
||||
sizeof(cleaned_in_value) - clean_pos,
|
||||
"%s,", pch);
|
||||
|
||||
if (written < 0 || written >= (int)(sizeof(cleaned_in_value) - clean_pos)) {
|
||||
// Buffer full or error, stop appending
|
||||
break;
|
||||
}
|
||||
clean_pos += written;
|
||||
}
|
||||
if (clean_pos > 0) {
|
||||
cleaned_in_value[clean_pos - 1] = '\0'; // Remove trailing comma
|
||||
}
|
||||
|
||||
// If curr_value matches cleaned_in_value directly
|
||||
if (strcmp(curr_value, cleaned_in_value) == 0)
|
||||
return true;
|
||||
|
||||
DM_STRNCPY(buf, curr_value, sizeof(buf));
|
||||
|
||||
char *is_list = strchr(buf, ';');
|
||||
|
||||
for (pch = strtok_r(buf, is_list ? ";" : ",", &pchr);
|
||||
|
|
@ -936,7 +962,8 @@ static bool is_same_reference_path(const char *curr_value, const char *in_value)
|
|||
resolved_path[pos - 1] = 0; // Remove trailing comma
|
||||
}
|
||||
|
||||
if (strcmp(resolved_path, in_value) == 0)
|
||||
// Compare resolved_path with cleaned_in_value
|
||||
if (strcmp(resolved_path, cleaned_in_value) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue