Skip to content

Commit 013a527

Browse files
committed
fixup: remove branch entirely instead of asserting
See review comments on #22273 for rationale. wchargin-branch: normalizeString-dead-branch
1 parent 757666c commit 013a527

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

lib/path.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121

2222
'use strict';
2323

24-
const {
25-
ERR_ASSERTION,
26-
ERR_INVALID_ARG_TYPE
27-
} = require('internal/errors').codes;
24+
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
2825
const {
2926
CHAR_UPPERCASE_A,
3027
CHAR_LOWERCASE_A,
@@ -80,23 +77,16 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
8077
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
8178
if (res.length > 2) {
8279
const lastSlashIndex = res.lastIndexOf(separator);
83-
if (lastSlashIndex !== res.length - 1) {
84-
if (lastSlashIndex === -1) {
85-
res = '';
86-
lastSegmentLength = 0;
87-
} else {
88-
res = res.slice(0, lastSlashIndex);
89-
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
90-
}
91-
lastSlash = i;
92-
dots = 0;
93-
continue;
80+
if (lastSlashIndex === -1) {
81+
res = '';
82+
lastSegmentLength = 0;
9483
} else {
95-
throw new ERR_ASSERTION(
96-
'invariant violation: unreachable: ' +
97-
JSON.stringify({ path, allowAboveRoot, separator })
98-
);
84+
res = res.slice(0, lastSlashIndex);
85+
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
9986
}
87+
lastSlash = i;
88+
dots = 0;
89+
continue;
10090
} else if (res.length === 2 || res.length === 1) {
10191
res = '';
10292
lastSegmentLength = 0;

0 commit comments

Comments
 (0)