You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
url(): userinfo with two or more colons accepts a trailing newline (%0A) #603
validators.url handles %0A differently depending on where it sits in the userinfo. When the userinfo has two or more colons, the value goes through unquote and then _username_regex().match(...). The non-quoted-string branch of that regex ends in $, which also matches before a trailing newline. A decoded \n at the end is therefore never checked, while the same %0A in the middle is rejected.
To reproduce
importvalidatorsmid="http://a:b:c%0Ad@example.com"# newline in the middleend="http://a:b:c%0A@example.com"# newline at the endprint("mid", validators.url(mid) isTrue, "end", validators.url(end) isTrue)
Output on master (22786cc) and on validators 0.36.0:
mid False end True
Expected behavior
end should be rejected like mid, so the script should print mid False end False. The non-quoted-string branch of _username_regex (url.py:22) excludes the newline character, but the trailing $ lets one through at the end of the string.
Cause: src/validators/url.py:81, _username_regex().match(unquote(value)), combined with $ at the end of the pattern. Using \Z instead of $ would make both cases behave the same. The same kind of trailing-newline problem was fixed for slug() in #492.
I know %0A is a legal percent-encoding in a URL, so this is about consistency rather than a spec violation.
I have a fix with a regression test ready and will open a pull request for it right after filing this issue; it will link back here.
Activity