Skip to content

Commit c90318b

Browse files
authored
Merge pull request #243 from oasis-open/claude-fix-180
Fix for issue #180 by Claude Code
2 parents 7f84263 + 58891e8 commit c90318b

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

docs/best-practices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ Mandatory Checks - STIX 2.1
9999
| | RFC 5646 language code | language code. |
100100
+---------------------------------+----------------------------------------+----------------------------------------+
101101
| software_language | the 'language' property of software | The 'languages' property of object |
102-
| | objects is a valid ISO 639-2 language | '<identifier>' contains an invalid |
103-
| | code | code ('<lang>'). |
102+
| | objects is a valid RFC 5646 language | '<identifier>' contains an invalid |
103+
| | code (ISO 639-2 accepted with warning) | code ('<lang>'). |
104104
+---------------------------------+----------------------------------------+----------------------------------------+
105105
| patterns | that the syntax of the pattern of an | '<object>' is not a valid observable |
106106
| | indicator is valid, and that objects | type name |

pinning-schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Output confirms the schema 2.1 correct commit is pinned:
1212
Entering 'stix2validator/schemas-2.0'
1313
stix2validator/schemas-2.0 b155093705ab4934ee29e7ba4dc99ed053cd4e7f
1414
Entering 'stix2validator/schemas-2.1'
15-
stix2validator/schemas-2.1 4d010b385b83e53ea322357783ff3be3da5820fb
15+
stix2validator/schemas-2.1 c4f8d589acf2bdb3783655c89e0ffb6e150006ae
1616

17-
Push from local to my repo (fork of Oasis) which then feeds the change to the PR on Oasis. I've updated the comments in the PR to confirm.
17+
Push from local to my repo (fork of Oasis) which then feeds the change to the PR on Oasis. I've updated the comments in the PR to confirm.

stix2validator/test/v21/observed_data_tests.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,41 @@ def test_software_language(self):
643643
}
644644
self.assertFalseWithOptions(observed_data)
645645

646-
observed_data['languages'][0] = 'eng'
646+
# Test with RFC 5646 language code (preferred)
647+
observed_data['languages'][0] = 'en'
647648
self.assertTrueWithOptions(observed_data)
648649

650+
def test_software_language_iso639_compatibility(self):
651+
"""Test that ISO 639-2 codes are accepted with warnings for backward compatibility"""
652+
import io
653+
import logging
654+
655+
# Capture log output
656+
log_capture = io.StringIO()
657+
handler = logging.StreamHandler(log_capture)
658+
handler.setLevel(logging.WARNING)
659+
logger = logging.getLogger('stix2validator.v21.musts')
660+
logger.addHandler(handler)
661+
logger.setLevel(logging.WARNING)
662+
663+
observed_data = {
664+
"type": "software",
665+
"id": "software--ff1e0780-358c-5808-a8c7-d0fca4ef6ef4",
666+
"name": "word",
667+
"languages": ["eng"] # ISO 639-2 code
668+
}
669+
670+
# Should be valid (backward compatibility)
671+
self.assertTrueWithOptions(observed_data)
672+
673+
# Should generate a warning
674+
log_output = log_capture.getvalue()
675+
self.assertIn("ISO 639-2 language code", log_output)
676+
self.assertIn("RFC 5646 language codes are preferred", log_output)
677+
678+
# Clean up
679+
logger.removeHandler(handler)
680+
649681
def test_software_cpe(self):
650682
observed_data = {
651683
"type": "software",

stix2validator/v21/musts.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,30 @@ def language(instance):
411411

412412
@cyber_observable_check("2.1")
413413
def software_language(instance):
414-
"""Ensure the 'language' property of software objects is a valid ISO 639-2
415-
language code.
414+
"""Ensure the 'language' property of software objects is a valid RFC 5646
415+
language code. ISO 639-2 codes are accepted for backward compatibility
416+
but will generate warnings.
416417
"""
417418
if ('type' in instance and instance['type'] == 'software' and
418419
'languages' in instance):
419420
for lang in instance['languages']:
420-
if lang not in enums.SOFTWARE_LANG_CODES:
421+
if lang in enums.LANG_CODES:
422+
# Valid RFC 5646 language code
423+
continue
424+
elif lang in enums.SOFTWARE_LANG_CODES:
425+
# ISO 639-2 code - accept but warn
426+
import logging
427+
logger = logging.getLogger(__name__)
428+
logger.warning("The 'languages' property of object '%s' "
429+
"contains an ISO 639-2 language code ('%s'). "
430+
"RFC 5646 language codes are preferred for STIX 2.1. "
431+
"Consider updating to RFC 5646 format."
432+
% (instance['id'], lang))
433+
else:
434+
# Invalid language code
421435
yield JSONError("The 'languages' property of object '%s' "
422-
"contains an invalid ISO 639-2 language "
423-
" code ('%s')."
436+
"contains an invalid language code ('%s'). "
437+
"Expected RFC 5646 language code."
424438
% (instance['id'], lang), instance['id'])
425439

426440

0 commit comments

Comments
 (0)