diff options
author | Francesco Giudici <fgiudici@redhat.com> | 2018-02-05 19:00:08 +0100 |
---|---|---|
committer | Francesco Giudici <fgiudici@redhat.com> | 2018-02-12 10:42:58 +0100 |
commit | 38844e6c5ead114f3ce3a7ea165c4db71eed19a4 (patch) | |
tree | 85775cd2b3ba9377c776df8124b4121441f60da6 /clients | |
parent | 350dbb55abf3a80267c398e6f64c2cee4645475a (diff) |
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.
Diffstat (limited to 'clients')
-rw-r--r-- | clients/common/nm-client-utils.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index 194271a86c..c312f8cdf7 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -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); |