From 2fb138167691fcad9225e4c77152000cf485ff60 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 7 Jun 2017 12:49:00 -0700 Subject: [PATCH 1/6] doc: document and test that methods return this Also, add tests to ensure they will always return this, and to confirm they return this when these doc changes are back-ported to earlier release lines. PR-URL: https://github.com/nodejs/node/pull/13553 Reviewed-By: Colin Ihrig Reviewed-By: Roman Reiss Reviewed-By: Luigi Pinca Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell --- test/parallel/test-net-end-close.js | 2 +- test/parallel/test-net-server-close.js | 6 +++--- test/parallel/test-net-socket-local-address.js | 9 ++++++--- test/parallel/test-net-stream.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-net-end-close.js b/test/parallel/test-net-end-close.js index d9f33fd7d8d1cf..44a539a3e800a6 100644 --- a/test/parallel/test-net-end-close.js +++ b/test/parallel/test-net-end-close.js @@ -14,7 +14,7 @@ const s = new net.Socket({ }, writable: false }); -s.resume(); +assert.strictEqual(s, s.resume()); const events = []; diff --git a/test/parallel/test-net-server-close.js b/test/parallel/test-net-server-close.js index 28519fdafdbc9c..5affadfac42930 100644 --- a/test/parallel/test-net-server-close.js +++ b/test/parallel/test-net-server-close.js @@ -23,7 +23,7 @@ let server = net.createServer(function(c) { sockets.push(c); if (sockets.length === 2) { - server.close(); + assert.strictEqual(server.close(), server); sockets.forEach(function(c) { c.destroy(); }); } }); @@ -32,7 +32,7 @@ server.on('close', function() { events.push('server'); }); -server.listen(0, function() { +assert.strictEqual(server, server.listen(0, function() { net.createConnection(this.address().port); net.createConnection(this.address().port); -}); +})); diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index e888667eab4c4f..19749bde9552b6 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -34,7 +34,10 @@ function connect() { conns++; client.once('close', connect); - client.connect(server.address().port, common.localhostIPv4, () => { - clientLocalPorts.push(client.localPort); - }); + assert.strictEqual( + client, + client.connect(server.address().port, common.localhostIPv4, () => { + clientLocalPorts.push(client.localPort); + }) + ); } diff --git a/test/parallel/test-net-stream.js b/test/parallel/test-net-stream.js index 9e1ca670e1e145..2d3cdd76be788f 100644 --- a/test/parallel/test-net-stream.js +++ b/test/parallel/test-net-stream.js @@ -39,7 +39,7 @@ const server = net.createServer(function(socket) { }).listen(0, function() { const conn = net.connect(this.address().port); conn.on('data', function(buf) { - conn.pause(); + assert.strictEqual(conn, conn.pause()); setTimeout(function() { conn.destroy(); }, 20); From dce4a7507094a9b3ad27275ca4fe8d567074737f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Thu, 29 Jun 2017 16:40:27 +0100 Subject: [PATCH 2/6] test: mark test-fs-readdir-ucs2 flaky PR-URL: https://github.com/nodejs/node/pull/13989 Reviewed-By: Refael Ackermann --- test/parallel/parallel.status | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 5b84bb1a250ee2..82c8c90a90824f 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -13,6 +13,7 @@ prefix parallel [$system==macos] [$arch==arm || $arch==arm64] +test-fs-readdir-ucs2 : PASS,FLAKY [$system==solaris] # Also applies to SmartOS test-debug-signal-cluster : PASS,FLAKY From 448c8d4d6495258f8416c2d2ea3a5086525b3064 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 1 Jul 2017 23:40:24 -0400 Subject: [PATCH 3/6] test: mark test-npm-install flaky on arm PR-URL: https://github.com/nodejs/node/pull/14035 Refs: https://github.com/nodejs/node/issues/14015 Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- test/parallel/parallel.status | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 82c8c90a90824f..97e7803f4d40a5 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -14,6 +14,7 @@ prefix parallel [$arch==arm || $arch==arm64] test-fs-readdir-ucs2 : PASS,FLAKY +test-npm-install: PASS,FLAKY [$system==solaris] # Also applies to SmartOS test-debug-signal-cluster : PASS,FLAKY From 3b2c79190ff00d6935838472de1d191c65a51d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 13 Jul 2017 16:02:37 +0200 Subject: [PATCH 4/6] build: run test-hash-seed at the end of test-v8 The v8 and test-hash-seed targets cannot be run in parallel because they need different copies of the deps/v8 directory. Ref: https://github.com/nodejs/node/pull/14004#issuecomment-314774773 PR-URL: https://github.com/nodejs/node/pull/14219 Reviewed-By: Michael Dawson Reviewed-By: Refael Ackermann Reviewed-By: Anna Henningsen --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6872ce2c7b8ba0..52bd44fa2e9227 100644 --- a/Makefile +++ b/Makefile @@ -296,13 +296,15 @@ test-timers-clean: ifneq ("","$(wildcard deps/v8/tools/run-tests.py)") -test-v8: v8 test-hash-seed +test-v8: v8 # note: performs full test unless QUICKCHECK is specified deps/v8/tools/run-tests.py --arch=$(V8_ARCH) \ --mode=$(BUILDTYPE_LOWER) $(V8_TEST_OPTIONS) $(QUICKCHECK_ARG) \ --no-presubmit \ --shell-dir=$(PWD)/deps/v8/out/$(V8_ARCH).$(BUILDTYPE_LOWER) \ $(TAP_V8) + @echo Testing hash seed + $(MAKE) test-hash-seed test-v8-intl: v8 # note: performs full test unless QUICKCHECK is specified From ddc8050c905197a04c1bfe667e040a62253dab0d Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 8 Jun 2017 02:00:33 +0300 Subject: [PATCH 5/6] cluster, dns, repl, tls, util: fix RegExp nits * Take RegExp creation out of cycles. * Use test(), not match() in boolean context. * Remove redundant RegExp parts. Backport-PR-URL: https://github.com/nodejs/node/pull/14348 PR-URL: https://github.com/nodejs/node/pull/13536 Reviewed-By: Anna Henningsen --- lib/_tls_wrap.js | 2 +- lib/cluster.js | 5 ++--- lib/dns.js | 6 ++++-- lib/repl.js | 7 ++++--- lib/util.js | 10 ++++++---- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index a4bda406f817cc..1960910258bd7d 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -954,7 +954,7 @@ function SNICallback(servername, callback) { var ctx; this.server._contexts.some(function(elem) { - if (servername.match(elem[0]) !== null) { + if (elem[0].test(servername)) { ctx = elem[1]; return true; } diff --git a/lib/cluster.js b/lib/cluster.js index 5307e09d6b5566..4bfa624a57e8c2 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -298,14 +298,13 @@ function masterInit() { var workerEnv = util._extend({}, process.env); var execArgv = cluster.settings.execArgv.slice(); var debugPort = 0; + var debugArgvRE = /^(--inspect|--debug|--debug-(brk|port))(=\d+)?$/; workerEnv = util._extend(workerEnv, env); workerEnv.NODE_UNIQUE_ID = '' + id; for (var i = 0; i < execArgv.length; i++) { - var match = execArgv[i].match( - /^(--inspect|--debug|--debug-(brk|port))(=\d+)?$/ - ); + var match = execArgv[i].match(debugArgvRE); if (match) { if (debugPort === 0) { diff --git a/lib/dns.js b/lib/dns.js index a86f498960b254..5ff28e4baceb5b 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -297,13 +297,15 @@ exports.setServers = function(servers) { // servers cares won't have any servers available for resolution const orig = cares.getServers(); const newSet = []; + const IPv6RE = /\[(.*)\]/; + const addrSplitRE = /:\d+$/; servers.forEach((serv) => { var ipVersion = isIP(serv); if (ipVersion !== 0) return newSet.push([ipVersion, serv]); - const match = serv.match(/\[(.*)\](?::\d+)?/); + const match = serv.match(IPv6RE); // we have an IPv6 in brackets if (match) { ipVersion = isIP(match[1]); @@ -311,7 +313,7 @@ exports.setServers = function(servers) { return newSet.push([ipVersion, match[1]]); } - const s = serv.split(/:\d+$/)[0]; + const s = serv.split(addrSplitRE)[0]; ipVersion = isIP(s); if (ipVersion !== 0) diff --git a/lib/repl.js b/lib/repl.js index 52bb1b6b53986c..2dfcc2899344a6 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -861,6 +861,7 @@ function complete(line, callback) { const exts = Object.keys(this.context.require.extensions); var indexRe = new RegExp('^index(' + exts.map(regexpEscape).join('|') + ')$'); + var versionedFileNamesRe = /-\d+\.\d+/; completeOn = match[1]; var subdir = match[2] || ''; @@ -879,7 +880,7 @@ function complete(line, callback) { name = files[f]; ext = path.extname(name); base = name.slice(0, -ext.length); - if (base.match(/-\d+\.\d+(\.\d+)?/) || name === '.npm') { + if (versionedFileNamesRe.test(base) || name === '.npm') { // Exclude versioned names that 'npm' installs. continue; } @@ -923,7 +924,7 @@ function complete(line, callback) { // spam.eggs.<|> # completions for 'spam.eggs' with filter '' // foo<|> # all scope vars with filter 'foo' // foo.<|> # completions for 'foo' with filter '' - } else if (line.length === 0 || line[line.length - 1].match(/\w|\.|\$/)) { + } else if (line.length === 0 || /\w|\.|\$/.test(line[line.length - 1])) { match = simpleExpressionRE.exec(line); if (line.length === 0 || match) { var expr; @@ -1175,7 +1176,7 @@ REPLServer.prototype.memory = function memory(cmd) { self.lines.level.push({ line: self.lines.length - 1, depth: depth, - isFunction: /\s*function\s*/.test(cmd) + isFunction: /\bfunction\b/.test(cmd) }); } else if (depth < 0) { // going... up. diff --git a/lib/util.js b/lib/util.js index b96c5121ed9610..635144818d8f63 100644 --- a/lib/util.js +++ b/lib/util.js @@ -17,6 +17,8 @@ const inspectDefaultOptions = Object.seal({ breakLength: 60 }); +const numbersOnlyRE = /^\d+$/; + var Debug; var simdFormatters; @@ -668,7 +670,7 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); } keys.forEach(function(key) { - if (typeof key === 'symbol' || !key.match(/^\d+$/)) { + if (typeof key === 'symbol' || !numbersOnlyRE.test(key)) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); } @@ -687,7 +689,7 @@ function formatTypedArray(ctx, value, recurseTimes, visibleKeys, keys) { output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); } for (const key of keys) { - if (typeof key === 'symbol' || !key.match(/^\d+$/)) { + if (typeof key === 'symbol' || !numbersOnlyRE.test(key)) { output.push( formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); } @@ -801,11 +803,11 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { } } if (name === undefined) { - if (array && key.match(/^\d+$/)) { + if (array && numbersOnlyRE.test(key)) { return str; } name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + if (/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/.test(name)) { name = name.substr(1, name.length - 2); name = ctx.stylize(name, 'name'); } else { From 17e00e3a3c949363c98edfb8de09c48efdbe59bf Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 16 Jun 2017 15:47:48 -0400 Subject: [PATCH 6/6] net: fix abort on bad address input PR-URL: https://github.com/nodejs/node/pull/13726 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/net.js | 10 +++++--- .../test-net-better-error-messages-path.js | 23 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/net.js b/lib/net.js index 5e653c61d2106c..4f1395ec2ed73a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -912,8 +912,9 @@ Socket.prototype.connect = function(options, cb) { this._sockname = null; } - var pipe = !!options.path; - debug('pipe', pipe, options.path); + const path = options.path; + var pipe = !!path; + debug('pipe', pipe, path); if (!this._handle) { this._handle = pipe ? new Pipe() : new TCP(); @@ -930,7 +931,10 @@ Socket.prototype.connect = function(options, cb) { this.writable = true; if (pipe) { - connect(this, options.path); + if (typeof path !== 'string') { + throw new TypeError('"path" option must be a string: ' + path); + } + connect(this, path); } else { lookupAndConnect(this, options); } diff --git a/test/parallel/test-net-better-error-messages-path.js b/test/parallel/test-net-better-error-messages-path.js index f4d00c7aebf055..5f6203a5c2fe45 100644 --- a/test/parallel/test-net-better-error-messages-path.js +++ b/test/parallel/test-net-better-error-messages-path.js @@ -2,12 +2,21 @@ const common = require('../common'); const net = require('net'); const assert = require('assert'); -const fp = '/tmp/fadagagsdfgsdf'; -const c = net.connect(fp); -c.on('connect', common.mustNotCall()); +{ + const fp = '/tmp/fadagagsdfgsdf'; + const c = net.connect(fp); -c.on('error', common.mustCall(function(e) { - assert.strictEqual(e.code, 'ENOENT'); - assert.strictEqual(e.message, `connect ENOENT ${fp}`); -})); + c.on('connect', common.mustNotCall()); + c.on('error', common.mustCall(function(e) { + assert.strictEqual(e.code, 'ENOENT'); + assert.strictEqual(e.message, `connect ENOENT ${fp}`); + })); +} + +{ + assert.throws( + () => net.createConnection({ path: {} }), + /"path" option must be a string: \[object Object]/ + ); +}