@@ -18,17 +18,37 @@ def test_unknown_type(opencti_stix2: OpenCTIStix2, caplog):
1818
1919
2020def test_convert_markdown (opencti_stix2 : OpenCTIStix2 ):
21+ # Matched pair is converted to backticks
2122 result = opencti_stix2 .convert_markdown (
2223 " my <code> is very </special> </code> to me"
2324 )
2425 assert " my ` is very </special> ` to me" == result
2526
2627
28+ def test_convert_markdown_multiple_pairs (opencti_stix2 : OpenCTIStix2 ):
29+ # Multiple matched pairs are all converted
30+ result = opencti_stix2 .convert_markdown ("<code>foo</code> and <code>bar</code>" )
31+ assert "`foo` and `bar`" == result
32+
33+
2734def test_convert_markdown_typo (opencti_stix2 : OpenCTIStix2 ):
28- result = opencti_stix2 .convert_markdown (
29- " my <code is very </special> </code> to me"
30- )
31- assert " my <code is very </special> ` to me" == result
35+ # Malformed opening tag (<code missing closing >) means no valid pair exists; nothing should be replaced
36+ text = " my <code is very </special> </code> to me"
37+ result = opencti_stix2 .convert_markdown (text )
38+ assert text == result
39+
40+
41+ def test_convert_markdown_literal_code_tag (opencti_stix2 : OpenCTIStix2 ):
42+ # A lone <code> without a matching </code> is literal content and must not be altered
43+ text = 'Run python3 -c "<code>" and pass it to subprocess.run(..., shell=True)'
44+ result = opencti_stix2 .convert_markdown (text )
45+ assert text == result
46+
47+
48+ def test_convert_markdown_mixed_matched_and_lone (opencti_stix2 : OpenCTIStix2 ):
49+ # A matched pair is converted, but a trailing lone <code> is left untouched
50+ result = opencti_stix2 .convert_markdown ("<code>foo</code> and <code>" )
51+ assert "`foo` and <code>" == result
3252
3353
3454def test_format_date_with_tz (opencti_stix2 : OpenCTIStix2 ):
0 commit comments