Skip to content

Commit 7fe92bd

Browse files
Adds support for emojis and more IDNA URLs (#161)
* Adds support for emojis and more IDNA URLs * Validates URLs with IPs ending in .0 or .255 This reverts commit 42ea2fd.
1 parent 99ea4da commit 7fe92bd

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

tests/test_url.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@
4242
u'http://مثال.إختبار',
4343
u'http://例子.测试',
4444
u'http://उदाहरण.परीक्षा',
45+
u'http://www.😉.com',
46+
u'http://😉.com/😁',
47+
u'http://উদাহরণ.বাংলা',
48+
u'http://xn--d5b6ci4b4b3a.xn--54b7fta0cc',
4549
u'http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com',
4650
u'http://1337.net',
4751
u'http://a.b-c.de',
4852
u'http://223.255.255.254',
53+
u'http://10.1.1.0',
4954
u'http://10.1.1.1',
5055
u'http://10.1.1.254',
56+
u'http://10.1.1.255',
5157
u'http://127.0.0.1:8080',
5258
u'http://127.0.10.150',
5359
u'http://localhost',
@@ -114,8 +120,6 @@ def test_returns_true_on_valid_public_url(address, public):
114120
'http://-a.b.co',
115121
'http://a.b-.co',
116122
'http://0.0.0.0',
117-
'http://10.1.1.0',
118-
'http://10.1.1.255',
119123
'http://224.1.1.1',
120124
'http://1.1.1.1.1',
121125
'http://123.123.123',

validators/url.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .utils import validator
44

55
ip_middle_octet = r"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
6-
ip_last_octet = r"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
6+
ip_last_octet = r"(?:\.(?:0|[1-9]\d?|1\d\d|2[0-4]\d|25[0-5]))"
77

88
regex = re.compile( # noqa: W605
99
r"^"
@@ -69,16 +69,19 @@
6969
r"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"
7070
r")\]|"
7171
# host name
72-
r"(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)"
72+
r"(?:(?:(?:xn--)|[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]-?)*"
73+
r"[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]+)"
7374
# domain name
74-
r"(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*"
75+
r"(?:\.(?:(?:xn--)|[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]-?)*"
76+
r"[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]+)*"
7577
# TLD identifier
76-
r"(?:\.(?:[a-z\u00a1-\uffff]{2,}))"
78+
r"(?:\.(?:(?:xn--[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]{2,})|"
79+
r"[a-z\u00a1-\uffff\U00010000-\U0010ffff]{2,}))"
7780
r")"
7881
# port number
7982
r"(?::\d{2,5})?"
8083
# resource path
81-
u"(?:/[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:@/]*)?"
84+
u"(?:/[-a-z\u00a1-\uffff\U00010000-\U0010ffff0-9._~%!$&'()*+,;=:@/]*)?"
8285
# query string
8386
r"(?:\?\S*)?"
8487
# fragment

0 commit comments

Comments
 (0)