From 9124de86dfe6151e370fa485ee2ae657c18e1f1f Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Thu, 1 Jun 2017 14:27:45 +0300 Subject: [PATCH] Add default value to MaskingFilter "fill" setting MXS-1261. If "fill" is not defined, an "X" is used as default. Setting an empty string as "fill" or "value" is disallowed. --- server/modules/filter/masking/maskingrules.cc | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/server/modules/filter/masking/maskingrules.cc b/server/modules/filter/masking/maskingrules.cc index 8b1c250c2..f95295348 100644 --- a/server/modules/filter/masking/maskingrules.cc +++ b/server/modules/filter/masking/maskingrules.cc @@ -413,19 +413,34 @@ auto_ptr create_rule_from_elements(json_t* pReplace, json_t* pValue = json_object_get(pWith, KEY_VALUE); json_t* pFill = json_object_get(pWith, KEY_FILL); - if ((pValue || pFill) && - (!pValue || json_is_string(pValue)) && - (!pFill || json_is_string(pFill))) + if (!pFill) { - sRule = create_rule_from_elements(pColumn, pTable, pDatabase, - pValue, pFill, - pApplies_to, pExempted); + // Allowed. Use default value for fill and add it to pWith. + pFill = json_string("X"); + if (pFill) + { + json_object_set_new(pWith, KEY_FILL, pFill); + } + else + { + MXS_ERROR("json_string() error, cannot produce a valid rule."); + } } - else + if (pFill) { - MXS_ERROR("The '%s' object of a masking rule does not have either '%s' " - "or '%s' as keys, or their values are not strings.", - KEY_WITH, KEY_VALUE, KEY_FILL); + if ((!pValue || (json_is_string(pValue) && json_string_length(pValue))) && + (json_is_string(pFill) && json_string_length(pFill))) + { + sRule = create_rule_from_elements(pColumn, pTable, pDatabase, + pValue, pFill, + pApplies_to, pExempted); + } + else + { + MXS_ERROR("One of the keys '%s' or '%s' of masking rule object '%s' " + "has a non-string value or the string is empty.", + KEY_VALUE, KEY_FILL, KEY_WITH); + } } } else