|
7 | 7 | from validators.uri import uri |
8 | 8 |
|
9 | 9 |
|
| 10 | +@pytest.mark.parametrize( |
| 11 | + "value", |
| 12 | + [ |
| 13 | + "http://example.com/CaseSensitive?key=Value", |
| 14 | + "https://example.com", |
| 15 | + "ftp://example.com/file.txt", |
| 16 | + "mailto:User@example.com", |
| 17 | + "file:///tmp/Readme.txt", |
| 18 | + "ipfs://QmYwAPJzv5CZsnAzt8auVZRnGiUncKEy6PBDoDeZ7hA9Rx", |
| 19 | + "magnet:?xt=urn:btih:0123456789012345678901234567890123456789", |
| 20 | + "tel:+1234567890", |
| 21 | + "data:text/plain;base64,SGVsbG8=", |
| 22 | + "urn:isbn:9780140328721", |
| 23 | + "urc:example", |
| 24 | + "telnet://example.com:23/", |
| 25 | + ], |
| 26 | +) |
| 27 | +@pytest.mark.parametrize("uppercase", [True, False]) |
| 28 | +def test_accepts_case_insensitive_schemes(value: str, uppercase: bool): |
| 29 | + """Accept uppercase and mixed-case spellings of supported URI schemes.""" |
| 30 | + scheme, separator, rest = value.partition(":") |
| 31 | + scheme = scheme.upper() if uppercase else scheme.capitalize() |
| 32 | + assert uri(scheme + separator + rest) is True |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize("value", ["HTTP://", "FILE:path.txt", "TELNET://example.com/path"]) |
| 36 | +def test_uppercase_schemes_still_validate_the_rest(value: str): |
| 37 | + """Apply scheme-specific validation after normalizing the scheme.""" |
| 38 | + assert not uri(value) |
| 39 | + |
| 40 | + |
10 | 41 | @pytest.mark.parametrize( |
11 | 42 | "value", |
12 | 43 | [ |
|
0 commit comments