From 945e3375aa71c0b8554addca7142d9cc5ca82c80 Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Fri, 9 Jul 2021 20:24:31 -0400 Subject: [PATCH] Fix extension registration to not only check nested properties for spec compliance, but also the toplevel properties, if any. --- stix2/registration.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stix2/registration.py b/stix2/registration.py index a37f76e..9fb2f49 100644 --- a/stix2/registration.py +++ b/stix2/registration.py @@ -1,3 +1,4 @@ +import itertools import re from . import registry, version @@ -144,7 +145,12 @@ def _register_extension( """ ext_type = new_extension._type - properties = new_extension._properties + + # Need to check both toplevel and nested properties + prop_groups = [new_extension._properties] + if hasattr(new_extension, "_toplevel_properties"): + prop_groups.append(new_extension._toplevel_properties) + prop_names = itertools.chain.from_iterable(prop_groups) _validate_type(ext_type, version) @@ -161,7 +167,7 @@ def _register_extension( ext_type, ) - for prop_name in properties.keys(): + for prop_name in prop_names: if not re.match(PREFIX_21_REGEX, prop_name): raise ValueError("Property name '%s' must begin with an alpha character." % prop_name)