From 1489175202c034ba75294858fcd3a895f2a72f8e Mon Sep 17 00:00:00 2001 From: Ken Gaillot Date: Feb 05 2021 06:23:12 +0000 Subject: Low: scheduler: treat NULL and empty string the same in literal attribute comparisons Previously, expand_value_source() returned NULL if the value was the empty string ("") only when value-source was "param" or "meta". If value-source was literal, it would return the empty string. This behavior shouldn't depend on value-source, so it now returns NULL when a literal value is the empty string. This could change the behavior for "defined"/"not_defined" checks, and comparisons against another NULL or empty string value (NULL compares less than empty strings). But the consistency seems worth it. (Another question not addressed here is whether NULL and empty string should compare as equal.) --- diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c index aa5d6ab..d69f449 100644 --- a/lib/pengine/rules.c +++ b/lib/pengine/rules.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2020 the Pacemaker project contributors + * Copyright 2004-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -1039,7 +1039,10 @@ expand_value_source(const char *value, const char *value_source, { GHashTable *table = NULL; - if (pcmk__str_eq(value_source, "param", pcmk__str_casei)) { + if (pcmk__str_empty(value)) { + return NULL; // value_source is irrelevant + + } else if (pcmk__str_eq(value_source, "param", pcmk__str_casei)) { table = match_data->params; } else if (pcmk__str_eq(value_source, "meta", pcmk__str_casei)) { @@ -1049,7 +1052,7 @@ expand_value_source(const char *value, const char *value_source, return value; } - if ((table == NULL) || pcmk__str_empty(value)) { + if (table == NULL) { return NULL; } return (const char *) g_hash_table_lookup(table, value);