diff --git a/stix2/pattern_visitor.py b/stix2/pattern_visitor.py index 10f70bb..6da41b5 100644 --- a/stix2/pattern_visitor.py +++ b/stix2/pattern_visitor.py @@ -259,7 +259,7 @@ class STIXPatternVisitorForSTIX2(): if isinstance(next, TerminalNode): property_path.append(self.instantiate("ListObjectPathComponent", current.property_name, next.getText())) i += 2 - if isinstance(next, IntegerConstant): + elif isinstance(next, IntegerConstant): property_path.append(self.instantiate("ListObjectPathComponent", current.property_name, next.value)) i += 2 else: diff --git a/stix2/test/v20/test_pattern_expressions.py b/stix2/test/v20/test_pattern_expressions.py index 0e0a9ca..cca327b 100644 --- a/stix2/test/v20/test_pattern_expressions.py +++ b/stix2/test/v20/test_pattern_expressions.py @@ -512,15 +512,20 @@ def test_parsing_start_stop_qualified_expression(): def test_parsing_mixed_boolean_expression_1(): - patt_obj = create_pattern_object("[a:b = 1 AND a:b = 2 OR a:b = 3]",) + patt_obj = create_pattern_object("[a:b = 1 AND a:b = 2 OR a:b = 3]") assert str(patt_obj) == "[a:b = 1 AND a:b = 2 OR a:b = 3]" def test_parsing_mixed_boolean_expression_2(): - patt_obj = create_pattern_object("[a:b = 1 OR a:b = 2 AND a:b = 3]",) + patt_obj = create_pattern_object("[a:b = 1 OR a:b = 2 AND a:b = 3]") assert str(patt_obj) == "[a:b = 1 OR a:b = 2 AND a:b = 3]" +def test_parsing_integer_index(): + patt_obj = create_pattern_object("[a:b[1]=2]") + assert str(patt_obj) == "[a:b[1] = 2]" + + def test_parsing_illegal_start_stop_qualified_expression(): with pytest.raises(ValueError): create_pattern_object("[ipv4-addr:value = '1.2.3.4'] START '2016-06-01' STOP '2017-03-12T08:30:00Z'", version="2.0") diff --git a/stix2/test/v21/test_pattern_expressions.py b/stix2/test/v21/test_pattern_expressions.py index b574e05..56273c0 100644 --- a/stix2/test/v21/test_pattern_expressions.py +++ b/stix2/test/v21/test_pattern_expressions.py @@ -654,6 +654,11 @@ def test_parsing_mixed_boolean_expression_2(): assert str(patt_obj) == "[a:b = 1 OR a:b = 2 AND a:b = 3]" +def test_parsing_integer_index(): + patt_obj = create_pattern_object("[a:b[1]=2]") + assert str(patt_obj) == "[a:b[1] = 2]" + + def test_parsing_multiple_slashes_quotes(): patt_obj = create_pattern_object("[ file:name = 'weird_name\\'' ]", version="2.1") assert str(patt_obj) == "[file:name = 'weird_name\\'']"