From 19407359944835a848c76be13135ad1d3e74c7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=99=93=E9=A3=9E?= Date: Wed, 25 Dec 2024 14:03:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBug-=E8=84=B1=E6=95=8F?= =?UTF-8?q?=E6=97=B6=E6=9C=AA=E5=A4=84=E7=90=86None=EF=BC=88=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E7=9A=84null=EF=BC=89=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=BB=93=E6=9E=9C=E4=B8=BA=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E7=9A=84'None'=E3=80=82=20(#2880)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * # xx * bug修复X * # xx * BUG * 数据库返回时添加了null结果。 * 如果为null或none或空字符串,则不脱敏直接返回。 --- sql/utils/data_masking.py | 3 +++ sql/utils/tests.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sql/utils/data_masking.py b/sql/utils/data_masking.py index 1b15d9db41..61ad93c9c1 100644 --- a/sql/utils/data_masking.py +++ b/sql/utils/data_masking.py @@ -141,6 +141,9 @@ def analyze_query_tree(select_list, instance): def regex(masking_rule, value): """利用正则表达式脱敏数据""" + # 如果为null或none或空字符串,则不脱敏直接返回。 + if not value: + return value rule_regex = masking_rule["rule_regex"] rule_type = masking_rule["rule_type"] diff --git a/sql/utils/tests.py b/sql/utils/tests.py index 512e0f5edd..bf75778ecd 100644 --- a/sql/utils/tests.py +++ b/sql/utils/tests.py @@ -608,6 +608,7 @@ def test_data_masking_not_hit_rules(self, _inception): @patch("sql.utils.data_masking.GoInceptionEngine") def test_data_masking_hit_rules_not_exists_star(self, _inception): + """数据库返回时添加了null结果。""" _inception.return_value.query_data_masking.return_value = [ { "index": 0, @@ -619,7 +620,7 @@ def test_data_masking_hit_rules_not_exists_star(self, _inception): } ] sql = """select phone from users;""" - rows = (("18888888888",), ("18888888889",), ("18888888810",)) + rows = (("18888888888",), (None,), ("18888888889",), ("18888888810",)) query_result = ReviewSet(column_list=["phone"], rows=rows, full_sql=sql) r = data_masking(self.ins, "archery", sql, query_result) print("test_data_masking_hit_rules_not_exists_star:", r.rows) @@ -627,6 +628,9 @@ def test_data_masking_hit_rules_not_exists_star(self, _inception): [ "188****8888", ], + [ + None, + ], [ "188****8889", ],