From 4229c380a2be444cf617317608007b0cae44a603 Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Thu, 26 Apr 2018 10:20:46 -0400 Subject: [PATCH] Fix make_constant when value is already a constant Fixes #171. --- stix2/patterns.py | 3 +++ stix2/test/test_pattern_expressions.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/stix2/patterns.py b/stix2/patterns.py index 23ce71b..3f9cbd9 100644 --- a/stix2/patterns.py +++ b/stix2/patterns.py @@ -147,6 +147,9 @@ class ListConstant(_Constant): def make_constant(value): + if isinstance(value, _Constant): + return value + try: return parse_into_datetime(value) except ValueError: diff --git a/stix2/test/test_pattern_expressions.py b/stix2/test/test_pattern_expressions.py index 74a7d0f..14e3774 100644 --- a/stix2/test/test_pattern_expressions.py +++ b/stix2/test/test_pattern_expressions.py @@ -372,3 +372,9 @@ def test_invalid_startstop_qualifier(): stix2.StartStopQualifier(datetime.date(2016, 6, 1), 'foo') assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo) + + +def test_make_constant_already_a_constant(): + str_const = stix2.StringConstant('Foo') + result = stix2.patterns.make_constant(str_const) + assert result is str_const