diff --git a/README.md b/README.md index a12765e..6e9e85c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ $ npm install node-zookeeper-client ```javascript var zookeeper = require('node-zookeeper-client'); +// ipv6 : zookeeper.createClient('[2001:db8:65:6c61:622e:6b72:010:3214]:4322') var client = zookeeper.createClient('localhost:2181'); var path = process.argv[2]; diff --git a/lib/ConnectionStringParser.js b/lib/ConnectionStringParser.js index 4e068df..1c95afc 100644 --- a/lib/ConnectionStringParser.js +++ b/lib/ConnectionStringParser.js @@ -59,6 +59,17 @@ function ConnectionStringParser(connectionString) { return item; }).forEach(function (item) { var parts = item.split(':'); + var ipEndIndex = item.lastIndexOf(']'); + + if (parts.length > 2 && ipEndIndex !== -1) { // IPv6 (RFC 3986) + // not use endsWith (ECMAScript 6) + parts = [item.substring(1, ipEndIndex)]; + + // use port number + if (ipEndIndex !== (item.length - 1)) { + parts.push(item.substring(item.lastIndexOf(':') + 1)); + } + } servers.push({ host : parts[0],