From 2c4e47de562a5b8b7df93267819e2d09e8276ac4 Mon Sep 17 00:00:00 2001 From: Rich Piazza Date: Fri, 20 Mar 2020 11:56:09 -0400 Subject: [PATCH] remove leading - from type name re --- stix2/core.py | 4 ++-- stix2/test/v21/test_custom.py | 15 ++++++++++++++- stix2/utils.py | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/stix2/core.py b/stix2/core.py index bd2b524..6f05bf9 100644 --- a/stix2/core.py +++ b/stix2/core.py @@ -10,7 +10,7 @@ import stix2 from .base import _Observable, _STIXBase from .exceptions import ParseError from .markings import _MarkingsMixin -from .utils import PREFIX_21_REGEX, TYPE_21_REGEX, TYPE_REGEX, _get_dict +from .utils import PREFIX_21_REGEX, TYPE_21_REGEX, TYPE_REGEX, EXT_21_REGEX, _get_dict STIX2_OBJ_MAPS = {} @@ -319,7 +319,7 @@ def _register_observable_extension( ext_type, ) else: # 2.1+ - if not re.match(TYPE_21_REGEX, ext_type): + if not re.match(EXT_21_REGEX, ext_type): raise ValueError( "Invalid extension type name '%s': must only contain the " "characters a-z (lowercase ASCII), 0-9, hyphen (-), " diff --git a/stix2/test/v21/test_custom.py b/stix2/test/v21/test_custom.py index 168c7fe..2bdca05 100644 --- a/stix2/test/v21/test_custom.py +++ b/stix2/test/v21/test_custom.py @@ -58,6 +58,19 @@ def test_identity_custom_property(): ) assert "must begin with an alpha character." in str(excinfo.value) + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: + stix2.v21.Identity( + id=IDENTITY_ID, + created="2015-12-21T19:59:11Z", + modified="2015-12-21T19:59:11Z", + name="John Smith", + identity_class="individual", + custom_properties={ + "_foo": "bar", + }, + ) + assert "must begin with an alpha character." in str(excinfo.value) + identity = stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", @@ -210,7 +223,7 @@ def test_invalid_custom_property_in_observed_data(): x_foo='bar', ) - assert "must begin with an alpha character." in str(excinfo.value) + assert "must begin with an alpha character." in str(excinfo.value) def test_custom_property_object_in_observable_extension(): diff --git a/stix2/utils.py b/stix2/utils.py index abec9a9..f2bac52 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -27,8 +27,8 @@ NOW = object() STIX_UNMOD_PROPERTIES = ['created', 'created_by_ref', 'id', 'type'] TYPE_REGEX = re.compile(r'^\-?[a-z0-9]+(-[a-z0-9]+)*\-?$') -TYPE_21_REGEX = re.compile(r'^\-?([a-z][a-z0-9]*)+(-[a-z0-9]+)*\-?$') -EXT_21_REGEX = re.compile(r'^\-?([a-z][a-z0-9]*)+(-[a-z0-9]+)*\-ext$') +TYPE_21_REGEX = re.compile(r'([a-z][a-z0-9]*)+(-[a-z0-9]+)*\-?$') +EXT_21_REGEX = re.compile(r'([a-z][a-z0-9]*)+(-[a-z0-9]+)*\-ext$') PREFIX_21_REGEX = re.compile(r'^[a-z].*')