Skip to content

Commit

Permalink
Merge pull request #233 from clenk/open-file-unicode
Browse files Browse the repository at this point in the history
Fix unicode errors when validating files
  • Loading branch information
rpiazza authored Apr 4, 2024
2 parents 2330398 + 538b7fa commit 5ebca8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions stix2validator/test/v21/misc_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'test_examples', 'identity.json')
IDENTITY_CUSTOM = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_examples', 'identity_custom.json')
IDENTITY_UNICODE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_examples', 'identity_unicode.json')
INVALID_BRACES = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_examples', 'invalid_braces.json')
INVALID_COMMA = os.path.join(os.path.dirname(os.path.realpath(__file__)),
Expand Down Expand Up @@ -71,6 +73,11 @@ def test_validate_file_warning(caplog):
assert re.search("Custom property .+ should ", caplog.text)


def test_validate_file_unicode(caplog):
results = validate_file(IDENTITY_UNICODE)
assert results.is_valid


def test_validate_file_invalid_brace(caplog):
results = validate_file(INVALID_BRACES)
assert not results.is_valid
Expand Down
9 changes: 9 additions & 0 deletions stix2validator/test/v21/test_examples/identity_unicode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "identity",
"spec_version": "2.1",
"id": "identity--8c6af861-7b20-41ef-9b59-6344fd872a8f",
"created": "2016-08-08T15:50:10.983Z",
"modified": "2016-08-08T15:50:10.983Z",
"name": "Heizölrückstoßabdämpfung",
"identity_class": "organization"
}
2 changes: 1 addition & 1 deletion stix2validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def validate_file(fn, options=None):
options = ValidationOptions(files=fn)

try:
with open(fn) as instance_file:
with open(fn, encoding="utf-8") as instance_file:
file_results.object_results = validate(instance_file, options)

except Exception as ex:
Expand Down

0 comments on commit 5ebca8c

Please sign in to comment.