Skip to content

Commit 027f734

Browse files
committed
Make version-parsing code use only ASCII chars, in accordance with PEP 440.
1 parent dd6b557 commit 027f734

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

readthedocs/projects/version_handling.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,16 @@ def version_windows(versions, major=1, minor=1, point=1):
111111

112112

113113
def parse_version_failsafe(version_string):
114+
if not isinstance(version_string, six.text_type):
115+
uni_version = version_string.decode('utf-8')
116+
else:
117+
uni_version = version_string
118+
114119
try:
115-
return Version(
116-
unicodedata.normalize('NFKD', six.text_type(version_string))
117-
)
120+
normalized_version = unicodedata.normalize('NFKD', uni_version)
121+
ascii_version = normalized_version.encode('ascii', 'ignore')
122+
final_form = ascii_version.decode('ascii')
123+
return Version(final_form)
118124
except (UnicodeError, InvalidVersion):
119125
return None
120126

0 commit comments

Comments
 (0)