Skip to content
Open
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
5 changes: 4 additions & 1 deletion unstructured/cleaners/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ def clean(
def bytes_string_to_string(text: str, encoding: str = "utf-8"):
"""Converts a string representation of a byte string to a regular string using the
specified encoding."""
text_bytes = bytes([ord(char) for char in text])
try:
text_bytes = text.encode("latin-1")
except UnicodeEncodeError:
raise ValueError("bytes must be in range(0, 256)") from None
formatted_encoding = format_encoding_str(encoding)
return text_bytes.decode(formatted_encoding)

Expand Down