mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 09:30:31 +01:00
client: fix nmc_string_is_valid ambiguous detection
when input matched the heading of two allowed values the match was reported as ambiguous without checking if there was a perfect match following: fixed. Example of a failing input: const char **allowed = [ "ipv4, ipv6, ip" ]; const char *input = "ip"; "ip" was detected as ambiguous.
This commit is contained in:
parent
350dbb55ab
commit
38844e6c5e
1 changed files with 11 additions and 9 deletions
|
|
@ -134,7 +134,7 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error)
|
|||
{
|
||||
const char **p;
|
||||
size_t input_ln, p_len;
|
||||
gboolean prev_match = FALSE;
|
||||
gboolean prev_match = FALSE, ambiguous = FALSE;
|
||||
const char *ret = NULL;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
|
@ -148,19 +148,21 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error)
|
|||
if (g_ascii_strncasecmp (input, *p, input_ln) == 0) {
|
||||
if (input_ln == p_len) {
|
||||
ret = *p;
|
||||
ambiguous = FALSE;
|
||||
break;
|
||||
}
|
||||
if (!prev_match)
|
||||
if (!prev_match) {
|
||||
ret = *p;
|
||||
else {
|
||||
g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"),
|
||||
input, ret, *p);
|
||||
return NULL;
|
||||
}
|
||||
prev_match = TRUE;
|
||||
prev_match = TRUE;
|
||||
} else
|
||||
ambiguous = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (ambiguous) {
|
||||
g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"),
|
||||
input, ret, *p);
|
||||
return NULL;
|
||||
}
|
||||
finish:
|
||||
if (ret == NULL) {
|
||||
char *valid_vals = g_strjoinv (", ", (char **) allowed);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue