From 6779963c58caa523e60b6abbdd1d9ef2ba313825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Wed, 18 Oct 2023 09:42:33 +0200 Subject: [PATCH] sort tags: buf fix for root_uid entries in tags --- src/web_interface/filter.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/web_interface/filter.py b/src/web_interface/filter.py index 4c1018f6a..daa4f4c3d 100644 --- a/src/web_interface/filter.py +++ b/src/web_interface/filter.py @@ -17,7 +17,7 @@ from re import Match from string import ascii_letters from time import localtime, strftime, struct_time, time -from typing import Union +from typing import Union, Iterable from common_helper_files import human_readable_file_size from flask import render_template @@ -287,8 +287,7 @@ def render_analysis_tags(tags, size=14): output = '' if tags: for plugin_name in sorted(tags): - # sort tags by "value" (the displayed text in the tag) - for key, tag in sorted(tags[plugin_name].items(), key=lambda t: t[1]['value']): + for key, tag in sorted(tags[plugin_name].items(), key=_sort_tags_key): if key == 'root_uid': continue color = tag['color'] if tag['color'] in TagColor.ALL else TagColor.BLUE @@ -302,6 +301,12 @@ def render_analysis_tags(tags, size=14): return output +def _sort_tags_key(tag_tuples: Iterable[tuple[str, dict]]) -> str: + # Sort tags by "value" (the displayed text in the tag). There can be 'root_uid' entries which are no dicts + _, tag_dict = tag_tuples + return tag_dict['value'] if isinstance(tag_dict, dict) else '' + + def fix_cwe(string): if 'CWE' in string: return string.split(']')[0].split('E')[-1]