From 457bc298c48c995dd6ce0a3593320ccfd3623bc5 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 29 Nov 2017 11:09:53 -0500 Subject: [PATCH] feat(url parser): better error message for slash in hostname ported from #1559 --- lib/url_parser.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/url_parser.js b/lib/url_parser.js index f59bf164be..1412045faa 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -198,7 +198,13 @@ function parseConnectionString(url, options) { for (i = 0; i < hosts.length; i++) { var r = parser.parse(f('mongodb://%s', hosts[i].trim())); if (r.path && r.path.indexOf(':') !== -1) { - throw new Error('Double colon in host identifier'); + // Not connecting to a socket so check for an extra slash in the hostname. + // Using String#split as perf is better than match. + if (r.path.split('/').length > 1 && r.path.indexOf('::') === -1) { + throw new Error('Slash in host identifier'); + } else { + throw new Error('Double colon in host identifier'); + } } }