Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2016-02-21 11:04:09 +0300
committerBrian White <mscdex@mscdex.net>2016-03-18 06:20:12 +0300
commit08085c49b6e49ecfffd638c6cd46f4de639ae4f4 (patch)
treed882dc5471198ae78faa1ea9d36fcdf8081ef020 /lib/path.js
parentaf09a9cc1b8cf446272abd85b33210da2e895314 (diff)
path: assert inputs are strings
This commit makes input type checking consistent across all path functions. PR-URL: https://github.com/nodejs/node/pull/5348 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'lib/path.js')
-rw-r--r--lib/path.js18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/path.js b/lib/path.js
index b42889ebfc7..000dd2359d6 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -734,8 +734,7 @@ const win32 = {
dirname: function dirname(path) {
- if (typeof path !== 'string')
- path = '' + path;
+ assertPath(path);
const len = path.length;
if (len === 0)
return '.';
@@ -839,8 +838,7 @@ const win32 = {
basename: function basename(path, ext) {
if (ext !== undefined && typeof ext !== 'string')
throw new TypeError('"ext" argument must be a string');
- if (typeof path !== 'string')
- path = '' + path;
+ assertPath(path);
var start = 0;
var end = -1;
var matchedSlash = true;
@@ -926,8 +924,7 @@ const win32 = {
extname: function extname(path) {
- if (typeof path !== 'string')
- path = '' + path;
+ assertPath(path);
var startDot = -1;
var startPart = 0;
var end = -1;
@@ -1364,8 +1361,7 @@ const posix = {
dirname: function dirname(path) {
- if (typeof path !== 'string')
- path = '' + path;
+ assertPath(path);
if (path.length === 0)
return '.';
var code = path.charCodeAt(0);
@@ -1396,8 +1392,7 @@ const posix = {
basename: function basename(path, ext) {
if (ext !== undefined && typeof ext !== 'string')
throw new TypeError('"ext" argument must be a string');
- if (typeof path !== 'string')
- path = '' + path;
+ assertPath(path);
var start = 0;
var end = -1;
@@ -1471,8 +1466,7 @@ const posix = {
extname: function extname(path) {
- if (typeof path !== 'string')
- path = '' + path;
+ assertPath(path);
var startDot = -1;
var startPart = 0;
var end = -1;