From 055110dab04678fe3716d9d292218830ee496d60 Mon Sep 17 00:00:00 2001 From: Arianit Uka Date: Thu, 21 Feb 2013 11:44:22 -0500 Subject: [PATCH] path: join throws TypeError on non-string args lib/path.js: - throws a TypeError on the filter if the argument is not a string. test/simple/test-path.js: - removed the test to check if non-string types are filtered. - added a test to check if path.join throws TypeError on arguments that are not strings. --- lib/path.js | 6 ++++++ test/simple/test-path.js | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/path.js b/lib/path.js index 6685399bdcb..9958630d7bf 100644 --- a/lib/path.js +++ b/lib/path.js @@ -198,6 +198,9 @@ if (isWindows) { // windows version exports.join = function() { function f(p) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to join must be strings'); + } return p && typeof p === 'string'; } @@ -349,6 +352,9 @@ if (isWindows) { exports.join = function() { var paths = Array.prototype.slice.call(arguments, 0); return exports.normalize(paths.filter(function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to join must be strings'); + } return p && typeof p === 'string'; }).join('/')); }; diff --git a/test/simple/test-path.js b/test/simple/test-path.js index cb75fc8e505..43bddfbe7ba 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -218,9 +218,7 @@ var joinTests = [['/', '//foo'], '/foo'], [['/', '', '/foo'], '/foo'], [['', '/', 'foo'], '/foo'], - [['', '/', '/foo'], '/foo'], - // filtration of non-strings. - [['x', true, 7, 'y', null, {}], 'x/y'] + [['', '/', '/foo'], '/foo'] ]; // Windows-specific join tests @@ -284,6 +282,13 @@ joinTests.forEach(function(test) { // assert.equal(actual, expected, message); }); assert.equal(failures.length, 0, failures.join('')); +var joinThrowTests = [true, false, 7, null, {}, undefined, [], NaN]; +joinThrowTests.forEach(function(test) { + assert.throws(function() { + path.join(test); + }, TypeError); +}); + // path normalize tests if (isWindows) {