path: simplify normalizeString · nodejs/node@9946c59 (original) (raw)

Original file line number Diff line number Diff line change
@@ -50,11 +50,11 @@ function isWindowsDeviceRoot(code) {
50 50
51 51 // Resolves . and .. elements in a path with directory names
52 52 function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
53 -var res = '';
54 -var lastSegmentLength = 0;
55 -var lastSlash = -1;
56 -var dots = 0;
57 -var code;
53 +let res = '';
54 +let lastSegmentLength = 0;
55 +let lastSlash = -1;
56 +let dots = 0;
57 +let code = 0;
58 58 for (var i = 0; i <= path.length; ++i) {
59 59 if (i < path.length)
60 60 code = path.charCodeAt(i);
@@ -66,7 +66,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
66 66 if (isPathSeparator(code)) {
67 67 if (lastSlash === i - 1 | dots === 1) {
68 68 // NOOP
69 -} else if (lastSlash !== i - 1 && dots === 2) {
69 +} else if (dots === 2) {
70 70 if (res.length < 2 | lastSegmentLength !== 2
71 71 res.charCodeAt(res.length - 1) !== CHAR_DOT |
72 72 res.charCodeAt(res.length - 2) !== CHAR_DOT) {
@@ -82,7 +82,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
82 82 lastSlash = i;
83 83 dots = 0;
84 84 continue;
85 -} else if (res.length === 2 | res.length === 1) {
85 +} else if (res.length !== 0) {
86 86 res = '';
87 87 lastSegmentLength = 0;
88 88 lastSlash = i;