We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 718eb4e commit a4e220dCopy full SHA for a4e220d
memorious/logic/http.py
@@ -439,6 +439,14 @@ def encoding(self) -> str | None:
439
raw = self.raw
440
if raw:
441
self._encoding = guess_file_encoding(io.BytesIO(raw))
442
+ # Charset detectors misidentify short ASCII/UTF-8 text as
443
+ # cp1252 or latin-1; prefer utf-8 when the content is valid
444
+ if self._encoding and self._encoding.lower() != "utf-8":
445
+ try:
446
+ raw.decode("utf-8")
447
+ self._encoding = "utf-8"
448
+ except UnicodeDecodeError:
449
+ pass
450
return self._encoding
451
452
@encoding.setter
0 commit comments