Skip to content

Commit ff49c84

Browse files
committed
Tweak utf-8 with BOM encoding conversion
1 parent 243104b commit ff49c84

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

latextools/utils/tex_log.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22
from itertools import chain
3-
import codecs
43
import os
54
import regex as re
65
import sublime
@@ -231,11 +230,12 @@ def parse_log_file(logfile: str | os.PathLike[str]) -> tuple[list[str], list[str
231230
charset = charset_from_bytes(content).best()
232231
if not charset:
233232
raise UnicodeError(f"Unable to detect encoding of {logfile}!")
234-
if charset.bom and charset.encoding == "utf_8":
235-
content = content[len(codecs.BOM_UTF8):]
233+
encoding = charset.encoding
234+
if charset.bom and encoding == "utf_8":
235+
encoding += "_sig"
236236

237237
# decode bytes
238-
text = content.decode(encoding=charset.encoding, errors="ignore")
238+
text = content.decode(encoding=encoding, errors="ignore")
239239
text = text.replace("\r\n", "\n").replace("\r", "\n")
240240
panel.run_command("append", {"characters": text})
241241
return parse_log_view(panel)

plugins/bibliography/new_bibliography.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def get_entries(self, *bib_files):
152152
continue
153153
encoding = charset_match.encoding
154154
if charset_match.bom and encoding == "utf_8":
155-
content = content[len(codecs.BOM_UTF8):]
155+
encoding += "_sig"
156156

157157
# decode bytes
158158
text = content.decode(encoding=encoding)

plugins/bibliography/traditional_bibliography.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def get_entries(self, *bib_files):
7474
continue
7575
encoding = charset_match.encoding
7676
if charset_match.bom and encoding == "utf_8":
77-
content = content[len(codecs.BOM_UTF8):]
77+
encoding += "_sig"
7878

7979
# decode bytes
8080
text = content.decode(encoding=encoding)

0 commit comments

Comments
 (0)