mirror of
https://github.com/data-privacy-stack/presidio.git
synced 2026-07-23 11:20:55 -05:00
Validate JsonAnalysisBuilder root type for clearer list handling
Agent-Logs-Url: https://github.com/microsoft/presidio/sessions/438db274-63ab-4a22-af9f-6f2f3b7296d2 Co-authored-by: omri374 <3776619+omri374@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1ca5c249b3
commit
5bce4abf5b
@@ -104,9 +104,15 @@ class JsonAnalysisBuilder(AnalysisBuilder):
|
||||
"""
|
||||
logger.debug("Starting JSON BatchAnalyzer analysis")
|
||||
key_recognizer_result_map = {}
|
||||
objects_to_analyze = data if isinstance(data, list) else [data]
|
||||
if not isinstance(data, (dict, list)):
|
||||
raise ValueError(
|
||||
"JsonAnalysisBuilder only supports dictionary input "
|
||||
"or lists of dictionaries."
|
||||
)
|
||||
|
||||
for json_object in objects_to_analyze:
|
||||
dict_list = data if isinstance(data, list) else [data]
|
||||
|
||||
for json_object in dict_list:
|
||||
if not isinstance(json_object, dict):
|
||||
raise ValueError(
|
||||
"Each element in the list must be a dictionary. "
|
||||
|
||||
@@ -163,6 +163,11 @@ def test_generate_analysis_json_with_top_level_list_of_objects(json_analysis_bui
|
||||
assert structured_analysis.entity_mapping["email"] == "EMAIL_ADDRESS"
|
||||
|
||||
|
||||
def test_generate_analysis_json_with_invalid_root_type_should_raise(json_analysis_builder):
|
||||
with pytest.raises(ValueError):
|
||||
json_analysis_builder.generate_analysis("not a json object")
|
||||
|
||||
|
||||
def test_analysis_json_when_default_threshold_is_high_then_only_email_passes(
|
||||
sample_json,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user