From ad9400ecfe75cfb704a7440f2a28055f50a550ca Mon Sep 17 00:00:00 2001 From: "Seth M. Larson" Date: Sun, 23 Dec 2018 15:50:16 -0600 Subject: [PATCH] Normalize percent-encoded bytes before comparison --- tests/test_requests.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 4bc1924f..89eff885 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -9,6 +9,7 @@ import pickle import collections import contextlib import warnings +import re import io import requests @@ -2418,9 +2419,17 @@ class TestPreparingURLs(object): ) ) def test_preparing_url(self, url, expected): + + def normalize_percent_encode(x): + # Helper function that normalizes equivalent + # percent-encoded bytes before comparisons + for c in re.findall(r'%[a-fA-F0-9]{2}', x): + x = x.replace(c, c.upper()) + return x + r = requests.Request('GET', url=url) p = r.prepare() - assert p.url == expected + assert normalize_percent_encode(p.url) == expected @pytest.mark.parametrize( 'url',