diff options
author | Brian White <mscdex@mscdex.net> | 2016-02-21 11:04:09 +0300 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2016-03-18 06:20:12 +0300 |
commit | 08085c49b6e49ecfffd638c6cd46f4de639ae4f4 (patch) | |
tree | d882dc5471198ae78faa1ea9d36fcdf8081ef020 /lib/path.js | |
parent | af09a9cc1b8cf446272abd85b33210da2e895314 (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.js | 18 |
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; |