Skip to content

Commit af50222

Browse files
authored
✨ Add encoding validation in parse_file() (#507)
1 parent e38d695 commit af50222

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

bibtexparser/entrypoint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import codecs
12
import warnings
23
from typing import Iterable
34
from typing import List
@@ -125,7 +126,13 @@ def parse_file(
125126
126127
:param encoding: Encoding of the .bib file. Default encoding is ``"UTF-8"``.
127128
:return: Library: Parsed BibTeX library
129+
:raises LookupError: If the specified encoding is not recognized.
128130
"""
131+
try:
132+
codecs.lookup(encoding)
133+
except LookupError:
134+
raise LookupError(f"Unknown encoding: {encoding!r}")
135+
129136
with open(path, encoding=encoding) as f:
130137
bibtex_str = f.read()
131138
return parse_string(

0 commit comments

Comments
 (0)