Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benedict/dicts/io/io_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def read_content_from_file(filepath: str, format: str | None = None) -> str:
binary_format = is_binary_format(format)
if binary_format:
return filepath
content = fsutil.read_file(filepath)
content = fsutil.read_file(filepath, encoding="utf-8-sig")
return str(content)


Expand Down
2 changes: 2 additions & 0 deletions tests/dicts/io/input/valid-content-bom.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,city
Anna,Berlin
1 change: 1 addition & 0 deletions tests/dicts/io/input/valid-content-bom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "Anna"}
6 changes: 6 additions & 0 deletions tests/dicts/io/test_io_dict_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def test_from_csv_with_valid_file_valid_content(self) -> None:
d = IODict(filepath, format="csv")
self.assertTrue(isinstance(d, dict))

def test_from_csv_with_valid_file_with_bom(self) -> None:
# Excel's "CSV UTF-8" starts the file with a byte order mark
filepath = self.input_path("valid-content-bom.csv")
d = IODict.from_csv(filepath)
self.assertEqual(d["values"], [{"name": "Anna", "city": "Berlin"}])

# def test_from_csv_with_valid_file_valid_content_invalid_format(self):
# filepath = self.input_path('valid-content.base64')
# with self.assertRaises(ValueError):
Expand Down
5 changes: 5 additions & 0 deletions tests/dicts/io/test_io_dict_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def test_from_json_with_invalid_data(self) -> None:
with self.assertRaises(ValueError):
IODict(j, format="json")

def test_from_json_with_valid_file_with_bom(self) -> None:
filepath = self.input_path("valid-content-bom.json")
d = IODict.from_json(filepath)
self.assertEqual(d, {"name": "Anna"})

def test_from_json_with_valid_file_valid_content(self) -> None:
filepath = self.input_path("valid-content.json")
# static method
Expand Down