Skip to content

Commit 9a87fd6

Browse files
authored
Merge pull request #49 from sethmlarson/ipv4-hosts
Fix regex for IPv4 hosts
2 parents 84a88d3 + 03bfa65 commit 9a87fd6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/rfc3986/abnf_regexp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
2626
DIGIT = '0123456789'
2727
# https://tools.ietf.org/html/rfc3986#section-2.3
28-
UNRESERVED = UNRESERVED_CHARS = ALPHA + DIGIT + '._!-'
28+
UNRESERVED = UNRESERVED_CHARS = ALPHA + DIGIT + r'._!-'
2929
UNRESERVED_CHARS_SET = set(UNRESERVED_CHARS)
3030
NON_PCT_ENCODED_SET = RESERVED_CHARS_SET.union(UNRESERVED_CHARS_SET)
3131
# We need to escape the '-' in this case:
@@ -75,7 +75,7 @@
7575
'%[0-9A-Fa-f]{2}', SUB_DELIMITERS_RE + UNRESERVED_RE
7676
)
7777
# The pattern for an IPv4 address, e.g., 192.168.255.255, 127.0.0.1,
78-
IPv4_RE = '([0-9]{1,3}.){3}[0-9]{1,3}'
78+
IPv4_RE = r'([0-9]{1,3}\.){3}[0-9]{1,3}'
7979
# Hexadecimal characters used in each piece of an IPv6 address
8080
HEXDIG_RE = '[0-9A-Fa-f]{1,4}'
8181
# Least-significant 32 bits of an IPv6 address
@@ -111,7 +111,7 @@
111111
*variations
112112
)
113113

114-
IPv_FUTURE_RE = 'v[0-9A-Fa-f]+.[%s]+' % (
114+
IPv_FUTURE_RE = r'v[0-9A-Fa-f]+\.[%s]+' % (
115115
UNRESERVED_RE + SUB_DELIMITERS_RE + ':'
116116
)
117117

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
'www.example.com',
2626
'localhost',
2727
'http-bin.org',
28-
'%2Fvar%2Frun%2Fsocket'
28+
'%2Fvar%2Frun%2Fsocket',
29+
'6g9m8V6', # Issue #48
2930
]
3031

3132
invalid_hosts = [

0 commit comments

Comments
 (0)