Skip to content

Commit 90e3a0d

Browse files
committed
Revert "PYTHON-4575 Remove hostname length check"
This reverts commit a3e9cfc.
1 parent a3e9cfc commit 90e3a0d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pymongo/srv_resolver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def __init__(
8484
except Exception:
8585
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
8686
self.__slen = len(self.__plist)
87+
if self.__slen < 2:
88+
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,))
8789

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

test/test_dns.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ def create_tests(cls):
183183

184184
class TestParsingErrors(PyMongoTestCase):
185185
def test_invalid_host(self):
186+
self.assertRaisesRegex(
187+
ConfigurationError,
188+
"Invalid URI host: mongodb is not",
189+
self.simple_client,
190+
"mongodb+srv://mongodb",
191+
)
192+
self.assertRaisesRegex(
193+
ConfigurationError,
194+
"Invalid URI host: mongodb.com is not",
195+
self.simple_client,
196+
"mongodb+srv://mongodb.com",
197+
)
186198
self.assertRaisesRegex(
187199
ConfigurationError,
188200
"Invalid URI host: an IP address is not",

0 commit comments

Comments
 (0)