Skip to content

Commit

Permalink
feat(url parser): better error message for slash in hostname
Browse files Browse the repository at this point in the history
ported from #1559
  • Loading branch information
Jessica Lord committed Nov 29, 2017
1 parent 1d30bf6 commit 457bc29
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down

0 comments on commit 457bc29

Please sign in to comment.