Skip to content

Commit

Permalink
Support CSV files with BOM signatures
Browse files Browse the repository at this point in the history
Fixes #10701
  • Loading branch information
kk7ds committed Jul 4, 2023
1 parent 37081be commit ca6f40e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chirp/drivers/generic_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def load(self, filename=None):

self._blank()

with open(self._filename, newline='', encoding='utf-8') as f:
with open(self._filename, newline='', encoding='utf-8-sig') as f:
return self._load(f)

def _load(self, f):
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_parse_legacy(self):
self.assertEqual('NFM', mem.mode)
self.assertEqual(12.5, mem.tuning_step)

def test_parse_modern(self):
with open(self.testfn, 'w', encoding='utf-8') as f:
def test_parse_modern(self, output_encoding='utf-8'):
with open(self.testfn, 'w', encoding=output_encoding) as f:
f.write(CHIRP_CSV_MODERN)
csv = generic_csv.CSVRadio(self.testfn)
mem = csv.get_memory(1)
Expand All @@ -72,6 +72,9 @@ def test_parse_modern(self):
self.assertEqual('5.0W', str(mem.power))
self.assertIn('UHF calling', mem.comment)

def test_parse_modern_bom(self):
self.test_parse_modern(output_encoding='utf-8-sig')

def test_parse_minimal(self):
with open(self.testfn, 'w', encoding='utf-8') as f:
f.write(CHIRP_CSV_MINIMAL)
Expand Down

0 comments on commit ca6f40e

Please sign in to comment.