From 18be26fc2a7f8d41b691762d826f235ae04f24fd Mon Sep 17 00:00:00 2001 From: Marcin Wielgoszewski Date: Thu, 22 Nov 2012 11:10:22 -0500 Subject: [PATCH] Back to issue #630, .isalnum() was sufficient in addressing the issue. Adding a try/except block just masks any issues that are raised here, issues that the developer should definitely be made aware of. --- requests/utils.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/requests/utils.py b/requests/utils.py index b3d33f4f..df25126b 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -473,21 +473,18 @@ def unquote_unreserved(uri): """Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. """ - try: - parts = uri.split('%') - for i in range(1, len(parts)): - h = parts[i][0:2] - if len(h) == 2 and h.isalnum(): - c = chr(int(h, 16)) - if c in UNRESERVED_SET: - parts[i] = c + parts[i][2:] - else: - parts[i] = '%' + parts[i] + parts = uri.split('%') + for i in range(1, len(parts)): + h = parts[i][0:2] + if len(h) == 2 and h.isalnum(): + c = chr(int(h, 16)) + if c in UNRESERVED_SET: + parts[i] = c + parts[i][2:] else: parts[i] = '%' + parts[i] - return ''.join(parts) - except ValueError: - return uri + else: + parts[i] = '%' + parts[i] + return ''.join(parts) def requote_uri(uri):