Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7118b8a

Browse filesBrowse files
nwoltmanrvagg
authored andcommitted
path: remove dead code in favor of unit tests
Remove dead code paths that are created by assertions that will never trigger. They may only trigger if either the `splitDeviceRe` or `splitPathRe` regular expressions are modified. If at some point they are modified, current unit tests will catch most of the resulting errors and this commit adds extra tests to catch the remaining errors. PR-URL: #2282 Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent 07a88b0 commit 7118b8a
Copy full SHA for 7118b8a

File tree

Expand file treeCollapse file tree

2 files changed

+10
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-15
lines changed
Open diff view settings
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+1-11Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function win32SplitPath(filename) {
7676
// Separate device+slash from tail
7777
var result = splitDeviceRe.exec(filename),
7878
device = (result[1] || '') + (result[2] || ''),
79-
tail = result[3] || '';
79+
tail = result[3];
8080
// Split the tail into dir, basename and extension
8181
var result2 = splitTailRe.exec(tail),
8282
dir = result2[1],
@@ -386,9 +386,6 @@ win32.parse = function(pathString) {
386386
assertPath(pathString);
387387

388388
var allParts = win32SplitPath(pathString);
389-
if (!allParts || allParts.length !== 4) {
390-
throw new TypeError("Invalid path '" + pathString + "'");
391-
}
392389
return {
393390
root: allParts[0],
394391
dir: allParts[0] + allParts[1].slice(0, -1),
@@ -590,13 +587,6 @@ posix.parse = function(pathString) {
590587
assertPath(pathString);
591588

592589
var allParts = posixSplitPath(pathString);
593-
if (!allParts || allParts.length !== 4) {
594-
throw new TypeError("Invalid path '" + pathString + "'");
595-
}
596-
allParts[1] = allParts[1] || '';
597-
allParts[2] = allParts[2] || '';
598-
allParts[3] = allParts[3] || '';
599-
600590
return {
601591
root: allParts[0],
602592
dir: allParts[0] + allParts[1].slice(0, -1),
Collapse file

‎test/parallel/test-path-parse-format.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-path-parse-format.js
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var winPaths = [
99
'\\foo\\C:',
1010
'file',
1111
'.\\file',
12+
'',
1213

1314
// unc
1415
'\\\\server\\share\\file_path',
@@ -32,7 +33,8 @@ var unixPaths = [
3233
'file',
3334
'.\\file',
3435
'./file',
35-
'C:\\foo'
36+
'C:\\foo',
37+
''
3638
];
3739

3840
var unixSpecialCaseFormatTests = [
@@ -52,8 +54,6 @@ var errors = [
5254
message: /Path must be a string. Received 1/},
5355
{method: 'parse', input: [],
5456
message: /Path must be a string. Received undefined/},
55-
// {method: 'parse', input: [''],
56-
// message: /Invalid path/}, // omitted because it's hard to trigger!
5757
{method: 'format', input: [null],
5858
message: /Parameter 'pathObject' must be an object, not/},
5959
{method: 'format', input: [''],
@@ -93,8 +93,13 @@ function checkErrors(path) {
9393
}
9494

9595
function checkParseFormat(path, paths) {
96-
paths.forEach(function(element, index, array) {
96+
paths.forEach(function(element) {
9797
var output = path.parse(element);
98+
assert.strictEqual(typeof output.root, 'string');
99+
assert.strictEqual(typeof output.dir, 'string');
100+
assert.strictEqual(typeof output.base, 'string');
101+
assert.strictEqual(typeof output.ext, 'string');
102+
assert.strictEqual(typeof output.name, 'string');
98103
assert.strictEqual(path.format(output), element);
99104
assert.strictEqual(output.dir, output.dir ? path.dirname(element) : '');
100105
assert.strictEqual(output.base, path.basename(element));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.