|
41 | 41 | pytest.param( |
42 | 42 | 'https://example.com/#Fragment', 'https://example.com/#Fragment', True, id='preserve_fragment_casing' |
43 | 43 | ), |
| 44 | + pytest.param('https://example.com/a/', 'https://example.com/a', False, id='remove_trailing_slash'), |
| 45 | + pytest.param('https://example.com/a/b', 'https://example.com/a/b', False, id='keep_literal_slash'), |
| 46 | + pytest.param('https://example.com/a%2Fb', 'https://example.com/a%2Fb', False, id='keep_encoded_slash'), |
| 47 | + pytest.param( |
| 48 | + 'https://example.com/a%2fb', 'https://example.com/a%2Fb', False, id='uppercase_lowercase_encoded_slash' |
| 49 | + ), |
| 50 | + pytest.param('https://example.com/a%2F', 'https://example.com/a%2F', False, id='keep_encoded_trailing_slash'), |
| 51 | + pytest.param( |
| 52 | + 'https://example.com/a%2F/', |
| 53 | + 'https://example.com/a%2F', |
| 54 | + False, |
| 55 | + id='remove_literal_slash_after_encoded_slash', |
| 56 | + ), |
| 57 | + pytest.param( |
| 58 | + 'https://example.com/a%252Fb', 'https://example.com/a%252Fb', False, id='keep_double_encoded_slash' |
| 59 | + ), |
| 60 | + pytest.param('https://example.com/a+b', 'https://example.com/a+b', False, id='keep_literal_plus'), |
| 61 | + pytest.param('https://example.com/a%2Bb', 'https://example.com/a%2Bb', False, id='keep_encoded_plus'), |
| 62 | + pytest.param( |
| 63 | + 'https://example.com/a%2bb', 'https://example.com/a%2Bb', False, id='uppercase_lowercase_encoded_plus' |
| 64 | + ), |
| 65 | + pytest.param('https://example.com/a%3Fb', 'https://example.com/a%3Fb', False, id='keep_encoded_question_mark'), |
| 66 | + pytest.param('https://example.com/%61%7E', 'https://example.com/a~', False, id='decode_unreserved_escapes'), |
| 67 | + pytest.param( |
| 68 | + 'https://example.com/a%2F/?z=2&utm_source=test&a=1#fragment', |
| 69 | + 'https://example.com/a%2F?a=1&z=2', |
| 70 | + False, |
| 71 | + id='encoded_slash_with_query_remove_fragment', |
| 72 | + ), |
| 73 | + pytest.param( |
| 74 | + 'https://example.com/a%2F/?z=2&utm_source=test&a=1#fragment', |
| 75 | + 'https://example.com/a%2F?a=1&z=2#fragment', |
| 76 | + True, |
| 77 | + id='encoded_slash_with_query_retain_fragment', |
| 78 | + ), |
44 | 79 | ], |
45 | 80 | ) |
46 | 81 | def test_normalize_url(url: str, expected_output: str, *, keep_url_fragment: bool) -> None: |
@@ -152,49 +187,7 @@ def test_compute_unique_key_with_whitespace_in_headers() -> None: |
152 | 187 | assert uk_2 == expected_output |
153 | 188 |
|
154 | 189 |
|
155 | | -@pytest.mark.parametrize( |
156 | | - ('path', 'expected_output'), |
157 | | - [ |
158 | | - pytest.param('/items/a%2Fb', 'https://example.com/items/a%2fb', id='encoded-slash'), |
159 | | - pytest.param('/items/a%2fb', 'https://example.com/items/a%2fb', id='lowercase-encoded-slash'), |
160 | | - pytest.param('/items/a%2F', 'https://example.com/items/a%2f', id='encoded-trailing-slash'), |
161 | | - pytest.param('/items/a%2f', 'https://example.com/items/a%2f', id='lowercase-encoded-trailing-slash'), |
162 | | - pytest.param('/items/a%2F/', 'https://example.com/items/a%2f', id='encoded-before-literal-trailing-slash'), |
163 | | - pytest.param('/items/a%252Fb', 'https://example.com/items/a%252fb', id='double-encoded-slash'), |
164 | | - pytest.param('/items/a%2Bb', 'https://example.com/items/a%2bb', id='encoded-plus'), |
165 | | - pytest.param('/items/a%2bb', 'https://example.com/items/a%2bb', id='lowercase-encoded-plus'), |
166 | | - pytest.param('/items/a+b', 'https://example.com/items/a+b', id='literal-plus'), |
167 | | - pytest.param('/items/a/b', 'https://example.com/items/a/b', id='literal-separator'), |
168 | | - pytest.param('/items/a', 'https://example.com/items/a', id='literal-path'), |
169 | | - ], |
170 | | -) |
171 | | -def test_compute_unique_key_encoded_path(path: str, expected_output: str) -> None: |
172 | | - """Keep encoded slashes and plus signs distinct from their literal forms in request keys.""" |
173 | | - assert compute_unique_key(f'https://example.com{path}') == expected_output |
174 | | - |
175 | | - |
176 | | -@pytest.mark.parametrize( |
177 | | - ('url', 'expected_output', 'keep_url_fragment'), |
178 | | - [ |
179 | | - pytest.param('https://example.com/a%2fb', 'https://example.com/a%2fb', False, id='escape-spelling'), |
180 | | - pytest.param('https://example.com/a%252fb', 'https://example.com/a%252fb', False, id='no-double-quoting'), |
181 | | - pytest.param('https://example.com/%61%7E', 'https://example.com/a~', False, id='unreserved-escapes'), |
182 | | - pytest.param('https://example.com/a%3Fb', 'https://example.com/a%3fb', False, id='escaped-question-mark'), |
183 | | - pytest.param('https://example.com/a/', 'https://example.com/a', False, id='literal-trailing-slash'), |
184 | | - pytest.param( |
185 | | - 'https://example.com/a%2F/?z=2&utm_source=test&a=1#fragment', |
186 | | - 'https://example.com/a%2f?a=1&z=2', |
187 | | - False, |
188 | | - id='query-filter-sort-drop-fragment', |
189 | | - ), |
190 | | - pytest.param( |
191 | | - 'https://example.com/a%2F/?z=2&utm_source=test&a=1#fragment', |
192 | | - 'https://example.com/a%2f?a=1&z=2#fragment', |
193 | | - True, |
194 | | - id='query-filter-sort-keep-fragment', |
195 | | - ), |
196 | | - ], |
197 | | -) |
198 | | -def test_normalize_url_encoded_path(url: str, expected_output: str, *, keep_url_fragment: bool) -> None: |
199 | | - """Preserve path escapes while retaining URL canonicalization and fragment controls.""" |
200 | | - assert normalize_url(url, keep_url_fragment=keep_url_fragment) == expected_output |
| 190 | +def test_compute_unique_key_keeps_encoded_slash() -> None: |
| 191 | + """An encoded slash in the path gives a different unique key than a literal slash.""" |
| 192 | + assert compute_unique_key('https://example.com/a%2Fb') == 'https://example.com/a%2Fb' |
| 193 | + assert compute_unique_key('https://example.com/a/b') == 'https://example.com/a/b' |
0 commit comments