Skip to content

Commit eb9aa94

Browse files
authored
Merge pull request splunk#502 from splunk/enclosed-ipv6-host
updated check for IPv6 addresses
2 parents 418a174 + f37c0d7 commit eb9aa94

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

splunklib/binding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ def _authority(scheme=DEFAULT_SCHEME, host=DEFAULT_HOST, port=DEFAULT_PORT):
347347
"http://splunk.utopia.net:471"
348348
349349
"""
350-
if ':' in host:
350+
# check if host is an IPv6 address and not enclosed in [ ]
351+
if ':' in host and not (host.startswith('[') and host.endswith(']')):
351352
# IPv6 addresses must be enclosed in [ ] in order to be well
352353
# formed.
353354
host = '[' + host + ']'

tests/test_binding.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ def test_ipv6_host(self):
190190
host="2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
191191
"https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8089")
192192

193+
def test_ipv6_host_enclosed(self):
194+
self.assertEqual(
195+
binding._authority(
196+
host="[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"),
197+
"https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8089")
198+
193199
def test_all_fields(self):
194200
self.assertEqual(
195201
binding._authority(

0 commit comments

Comments
 (0)