summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js6
-rw-r--r--lib/net.js14
-rw-r--r--lib/url.js4
3 files changed, 19 insertions, 5 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index dce0862d9..13f701ba2 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -88,6 +88,12 @@ function Buffer(subject, encoding) {
poolOffset,
poolOffset + this.length);
poolOffset += this.length;
+
+ // Ensure aligned slices
+ if (poolOffset & 0x7) {
+ poolOffset |= 0x7;
+ poolOffset++;
+ }
} else {
alloc(this, this.length);
}
diff --git a/lib/net.js b/lib/net.js
index 2b0afa578..cef0475fa 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -895,7 +895,7 @@ Socket.prototype.connect = function(options, cb) {
} else {
var dns = require('dns');
var host = options.host || 'localhost';
- var port = options.port | 0;
+ var port = 0;
var localAddress = options.localAddress;
var localPort = options.localPort;
var dnsopts = {
@@ -909,8 +909,16 @@ Socket.prototype.connect = function(options, cb) {
if (localPort && !util.isNumber(localPort))
throw new TypeError('localPort should be a number: ' + localPort);
- if (port <= 0 || port > 65535)
- throw new RangeError('port should be > 0 and < 65536: ' + port);
+ if (typeof options.port === 'number')
+ port = options.port;
+ else if (typeof options.port === 'string')
+ port = options.port.trim() === '' ? -1 : +options.port;
+ else if (options.port !== undefined)
+ throw new TypeError('port should be a number or string: ' + options.port);
+
+ if (port < 0 || port > 65535 || isNaN(port))
+ throw new RangeError('port should be >= 0 and < 65536: ' +
+ options.port);
if (dnsopts.family !== 4 && dnsopts.family !== 6)
dnsopts.hints = dns.ADDRCONFIG | dns.V4MAPPED;
diff --git a/lib/url.js b/lib/url.js
index c5a3793b9..1c7506023 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -641,8 +641,8 @@ Url.prototype.resolveObject = function(relative) {
// then it must NOT get a trailing slash.
var last = srcPath.slice(-1)[0];
var hasTrailingSlash = (
- (result.host || relative.host || srcPath.length > 1) &&
- (last === '.' || last === '..') || last === '');
+ (result.host || relative.host) && (last === '.' || last === '..') ||
+ last === '');
// strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0