Skip to content

Commit 457bc29

Browse files
author
Jessica Lord
committed
feat(url parser): better error message for slash in hostname
ported from #1559
1 parent 1d30bf6 commit 457bc29

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/url_parser.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ function parseConnectionString(url, options) {
198198
for (i = 0; i < hosts.length; i++) {
199199
var r = parser.parse(f('mongodb://%s', hosts[i].trim()));
200200
if (r.path && r.path.indexOf(':') !== -1) {
201-
throw new Error('Double colon in host identifier');
201+
// Not connecting to a socket so check for an extra slash in the hostname.
202+
// Using String#split as perf is better than match.
203+
if (r.path.split('/').length > 1 && r.path.indexOf('::') === -1) {
204+
throw new Error('Slash in host identifier');
205+
} else {
206+
throw new Error('Double colon in host identifier');
207+
}
202208
}
203209
}
204210

0 commit comments

Comments
 (0)