File tree 1 file changed +12
-6
lines changed
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -107,12 +107,18 @@ def get_coding(text):
107
107
@return coding string
108
108
"""
109
109
for line in text .splitlines ()[:2 ]:
110
- result = CODING_RE .search (to_text_string (line ))
111
- if result :
112
- codec = result .group (1 )
113
- # sometimes we find a false encoding that can result in errors
114
- if codec in CODECS :
115
- return codec
110
+ try :
111
+ result = CODING_RE .search (to_text_string (line ))
112
+ except UnicodeDecodeError :
113
+ # This could fail because to_text_string assume the text is utf8-like
114
+ # and we don't know the encoding to give it to to_text_string
115
+ pass
116
+ else :
117
+ if result :
118
+ codec = result .group (1 )
119
+ # sometimes we find a false encoding that can result in errors
120
+ if codec in CODECS :
121
+ return codec
116
122
117
123
# Fallback using chardet
118
124
if is_binary_string (text ):
You can’t perform that action at this time.
0 commit comments