aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2022-01-01 17:11:43 +0100
committerJ08nY2022-01-03 20:50:13 +0100
commit3568c33bbe132ca2285913f96a361751a164fa2e (patch)
tree42ad24dba12858560c23761b37abc2c94bf94c77
parent54662ab4500e12e290b43b6c22d7547516d5ce82 (diff)
downloadsec-certs-3568c33bbe132ca2285913f96a361751a164fa2e.tar.gz
sec-certs-3568c33bbe132ca2285913f96a361751a164fa2e.tar.zst
sec-certs-3568c33bbe132ca2285913f96a361751a164fa2e.zip
Keep ordering of version matches in heuristics.
-rw-r--r--sec_certs/helpers.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/sec_certs/helpers.py b/sec_certs/helpers.py
index d6404d42..90e250d8 100644
--- a/sec_certs/helpers.py
+++ b/sec_certs/helpers.py
@@ -832,16 +832,21 @@ def compute_heuristics_version(cert_name: str) -> List[str]:
full_regex_string = r"|".join([without_version, short_version, long_version])
normalizer = r"(\d+\.*)+"
- matched_strings = set([max(x, key=len) for x in re.findall(full_regex_string, cert_name, re.IGNORECASE)])
+ matched_strings = [max(x, key=len) for x in re.findall(full_regex_string, cert_name, re.IGNORECASE)]
if not matched_strings:
- matched_strings = set([max(x, key=len) for x in re.findall(at_least_something, cert_name, re.IGNORECASE)])
+ matched_strings = [max(x, key=len) for x in re.findall(at_least_something, cert_name, re.IGNORECASE)]
+ # Only keep the first occurrence but keep order.
+ matches = []
+ for match in matched_strings:
+ if match not in matches:
+ matches.append(match)
# identified_versions = list(set([max(x, key=len) for x in re.findall(VERSION_PATTERN, cert_name, re.IGNORECASE | re.VERBOSE)]))
# return identified_versions if identified_versions else ['-']
- if not matched_strings:
+ if not matches:
return ["-"]
- matched = [re.search(normalizer, x) for x in matched_strings]
+ matched = [re.search(normalizer, x) for x in matches]
return [x.group() for x in matched if x is not None]