Skip to content

Commit

Permalink
fixup: remove branch entirely instead of asserting
Browse files Browse the repository at this point in the history
See review comments on #22273 for rationale.

wchargin-branch: normalizeString-dead-branch
  • Loading branch information
wchargin committed Aug 21, 2018
1 parent 757666c commit 013a527
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

'use strict';

const {
ERR_ASSERTION,
ERR_INVALID_ARG_TYPE
} = require('internal/errors').codes;
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
const {
CHAR_UPPERCASE_A,
CHAR_LOWERCASE_A,
Expand Down Expand Up @@ -80,23 +77,16 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
if (res.length > 2) {
const lastSlashIndex = res.lastIndexOf(separator);
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
}
lastSlash = i;
dots = 0;
continue;
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
throw new ERR_ASSERTION(
'invariant violation: unreachable: ' +
JSON.stringify({ path, allowAboveRoot, separator })
);
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
}
lastSlash = i;
dots = 0;
continue;
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSegmentLength = 0;
Expand Down

0 comments on commit 013a527

Please sign in to comment.