Skip to content

Commit 4cad3d7

Browse files
committed
PYTHON-4575 Remove hostname length check
1 parent 2149567 commit 4cad3d7

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pymongo/asynchronous/srv_resolver.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def __init__(
9696
except Exception:
9797
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
9898
self.__slen = len(self.__plist)
99-
if self.__slen < 2:
100-
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,))
10199

102100
async def get_options(self) -> Optional[str]:
103101
from dns import resolver

pymongo/synchronous/srv_resolver.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def __init__(
9696
except Exception:
9797
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
9898
self.__slen = len(self.__plist)
99-
if self.__slen < 2:
100-
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,))
10199

102100
def get_options(self) -> Optional[str]:
103101
from dns import resolver

test/test_uri_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
sys.path[0:0] = [""]
2525

2626
from test import unittest
27+
from unittest.mock import patch
2728

2829
from bson.binary import JAVA_LEGACY
2930
from pymongo import ReadPreference
@@ -553,6 +554,11 @@ def test_port_with_whitespace(self):
553554
with self.assertRaisesRegex(ValueError, r"Port contains whitespace character: '\\n'"):
554555
parse_uri("mongodb://localhost:27\n017")
555556

557+
def test_allow_srv_hosts_with_fewer_than_three_dot_separated_parts(self):
558+
with patch("dns.resolver.resolve"):
559+
parse_uri("mongodb+srv://localhost/")
560+
parse_uri("mongodb+srv://mongo.local/")
561+
556562

557563
if __name__ == "__main__":
558564
unittest.main()

0 commit comments

Comments
 (0)