| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ function normalizeStringWin32(path, allowAboveRoot) { | |||
| 14 | 14 | var lastSlash = -1; | |
| 15 | 15 | var dots = 0; | |
| 16 | 16 | var code; | |
| 17 | + var isAboveRoot = false; | ||
| 17 | 18 | for (var i = 0; i <= path.length; ++i) { | |
| 18 | 19 | if (i < path.length) | |
| 19 | 20 | code = path.charCodeAt(i); | |
@@ -25,7 +26,7 @@ function normalizeStringWin32(path, allowAboveRoot) { | |||
| 25 | 26 | if (lastSlash === i - 1 || dots === 1) { | |
| 26 | 27 | // NOOP | |
| 27 | 28 | } else if (lastSlash !== i - 1 && dots === 2) { | |
| 28 | - if (res.length < 2 || | ||
| 29 | + if (res.length < 2 || !isAboveRoot || | ||
| 29 | 30 | res.charCodeAt(res.length - 1) !== 46/*.*/ || | |
| 30 | 31 | res.charCodeAt(res.length - 2) !== 46/*.*/) { | |
| 31 | 32 | if (res.length > 2) { | |
@@ -42,12 +43,14 @@ function normalizeStringWin32(path, allowAboveRoot) { | |||
| 42 | 43 | res = res.slice(0, j); | |
| 43 | 44 | lastSlash = i; | |
| 44 | 45 | dots = 0; | |
| 46 | + isAboveRoot = false; | ||
| 45 | 47 | continue; | |
| 46 | 48 | } | |
| 47 | 49 | } else if (res.length === 2 || res.length === 1) { | |
| 48 | 50 | res = ''; | |
| 49 | 51 | lastSlash = i; | |
| 50 | 52 | dots = 0; | |
| 53 | + isAboveRoot = false; | ||
| 51 | 54 | continue; | |
| 52 | 55 | } | |
| 53 | 56 | } | |
@@ -56,12 +59,14 @@ function normalizeStringWin32(path, allowAboveRoot) { | |||
| 56 | 59 | res += '\\..'; | |
| 57 | 60 | else | |
| 58 | 61 | res = '..'; | |
| 62 | + isAboveRoot = true; | ||
| 59 | 63 | } | |
| 60 | 64 | } else { | |
| 61 | 65 | if (res.length > 0) | |
| 62 | 66 | res += '\\' + path.slice(lastSlash + 1, i); | |
| 63 | 67 | else | |
| 64 | 68 | res = path.slice(lastSlash + 1, i); | |
| 69 | + isAboveRoot = false; | ||
| 65 | 70 | } | |
| 66 | 71 | lastSlash = i; | |
| 67 | 72 | dots = 0; | |
@@ -80,6 +85,7 @@ function normalizeStringPosix(path, allowAboveRoot) { | |||
| 80 | 85 | var lastSlash = -1; | |
| 81 | 86 | var dots = 0; | |
| 82 | 87 | var code; | |
| 88 | + var isAboveRoot = false; | ||
| 83 | 89 | for (var i = 0; i <= path.length; ++i) { | |
| 84 | 90 | if (i < path.length) | |
| 85 | 91 | code = path.charCodeAt(i); | |
@@ -91,7 +97,7 @@ function normalizeStringPosix(path, allowAboveRoot) { | |||
| 91 | 97 | if (lastSlash === i - 1 || dots === 1) { | |
| 92 | 98 | // NOOP | |
| 93 | 99 | } else if (lastSlash !== i - 1 && dots === 2) { | |
| 94 | - if (res.length < 2 || | ||
| 100 | + if (res.length < 2 || !isAboveRoot || | ||
| 95 | 101 | res.charCodeAt(res.length - 1) !== 46/*.*/ || | |
| 96 | 102 | res.charCodeAt(res.length - 2) !== 46/*.*/) { | |
| 97 | 103 | if (res.length > 2) { | |
@@ -108,12 +114,14 @@ function normalizeStringPosix(path, allowAboveRoot) { | |||
| 108 | 114 | res = res.slice(0, j); | |
| 109 | 115 | lastSlash = i; | |
| 110 | 116 | dots = 0; | |
| 117 | + isAboveRoot = false; | ||
| 111 | 118 | continue; | |
| 112 | 119 | } | |
| 113 | 120 | } else if (res.length === 2 || res.length === 1) { | |
| 114 | 121 | res = ''; | |
| 115 | 122 | lastSlash = i; | |
| 116 | 123 | dots = 0; | |
| 124 | + isAboveRoot = false; | ||
| 117 | 125 | continue; | |
| 118 | 126 | } | |
| 119 | 127 | } | |
@@ -122,12 +130,14 @@ function normalizeStringPosix(path, allowAboveRoot) { | |||
| 122 | 130 | res += '/..'; | |
| 123 | 131 | else | |
| 124 | 132 | res = '..'; | |
| 133 | + isAboveRoot = true; | ||
| 125 | 134 | } | |
| 126 | 135 | } else { | |
| 127 | 136 | if (res.length > 0) | |
| 128 | 137 | res += '/' + path.slice(lastSlash + 1, i); | |
| 129 | 138 | else | |
| 130 | 139 | res = path.slice(lastSlash + 1, i); | |
| 140 | + isAboveRoot = false; | ||
| 131 | 141 | } | |
| 132 | 142 | lastSlash = i; | |
| 133 | 143 | dots = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -411,6 +411,11 @@ assert.strictEqual(path.win32.normalize('C:..\\..\\abc\\..\\def'), | |||
| 411 | 411 | 'C:..\\..\\def'); | |
| 412 | 412 | assert.strictEqual(path.win32.normalize('C:\\.'), 'C:\\'); | |
| 413 | 413 | assert.strictEqual(path.win32.normalize('file:stream'), 'file:stream'); | |
| 414 | + assert.strictEqual(path.win32.normalize('bar\\foo..\\..\\'), 'bar\\'); | ||
| 415 | + assert.strictEqual(path.win32.normalize('bar\\foo..\\..'), 'bar'); | ||
| 416 | + assert.strictEqual(path.win32.normalize('bar\\foo..\\..\\baz'), 'bar\\baz'); | ||
| 417 | + assert.strictEqual(path.win32.normalize('bar\\foo..\\'), 'bar\\foo..\\'); | ||
| 418 | + assert.strictEqual(path.win32.normalize('bar\\foo..'), 'bar\\foo..'); | ||
| 414 | 419 | ||
| 415 | 420 | assert.strictEqual(path.posix.normalize('./fixtures///b/../b/c.js'), | |
| 416 | 421 | 'fixtures/b/c.js'); | |
@@ -420,6 +425,11 @@ assert.strictEqual(path.posix.normalize('a//b//./c'), 'a/b/c'); | |||
| 420 | 425 | assert.strictEqual(path.posix.normalize('a//b//.'), 'a/b'); | |
| 421 | 426 | assert.strictEqual(path.posix.normalize('/a/b/c/../../../x/y/z'), '/x/y/z'); | |
| 422 | 427 | assert.strictEqual(path.posix.normalize('///..//./foo/.//bar'), '/foo/bar'); | |
| 428 | + assert.strictEqual(path.posix.normalize('bar/foo../../'), 'bar/'); | ||
| 429 | + assert.strictEqual(path.posix.normalize('bar/foo../..'), 'bar'); | ||
| 430 | + assert.strictEqual(path.posix.normalize('bar/foo../../baz'), 'bar/baz'); | ||
| 431 | + assert.strictEqual(path.posix.normalize('bar/foo../'), 'bar/foo../'); | ||
| 432 | + assert.strictEqual(path.posix.normalize('bar/foo..'), 'bar/foo..'); | ||
| 423 | 433 | ||
| 424 | 434 | ||
| 425 | 435 | // path.resolve tests | |
| Back | FazBrowse Home | New Git URL |
0 commit comments