Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/validators/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def _username_regex():
# extended latin
r"(^[\u0100-\u017F\u0180-\u024F]"
# dot-atom
+ r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
+ r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*\Z"
# non-quoted-string
+ r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*$)",
+ r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*\Z)",
re.IGNORECASE,
)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,22 @@ def test_url_accepts_percent_encoded_controls(encoded: str, template: str):
assert url(template.format(encoded=encoded)) is True


@pytest.mark.parametrize(
"value",
[
"http://a:b:c%0A@example.com",
"http://a:b:c%0a@example.com",
"https://user:pass:word%0A@example.com:8080/",
"http://a:b:c%0Ad@example.com",
"http://%0A:b:c@example.com",
"http://a:b:c%0A%0A@example.com",
],
)
def test_returns_failed_validation_on_newline_in_decoded_userinfo(value: str):
"""Test returns failed validation on a percent-encoded newline in a multi-colon userinfo."""
assert isinstance(url(value), ValidationError)


@pytest.mark.parametrize(
"value",
["https://example.\uff43\uff4f\uff4d/", "https://exam\u00adple.com/", "http://\u017ferver/"],
Expand Down