MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / normalizeArray

Function normalizeArray

packages/core/src/utils/path.ts:26–50  ·  view source on GitHub ↗

JSDoc

(parts: string[], allowAboveRoot?: boolean)

Source from the content-addressed store, hash-verified

24
25/** JSDoc */
26function normalizeArray(parts: string[], allowAboveRoot?: boolean): string[] {
27 // if the path tries to go above the root, `up` ends up > 0
28 let up = 0;
29 for (let i = parts.length - 1; i >= 0; i--) {
30 const last = parts[i];
31 if (last === '.') {
32 parts.splice(i, 1);
33 } else if (last === '..') {
34 parts.splice(i, 1);
35 up++;
36 } else if (up) {
37 parts.splice(i, 1);
38 up--;
39 }
40 }
41
42 // if the path is allowed to go above the root, restore leading ..s
43 if (allowAboveRoot) {
44 for (; up--; up) {
45 parts.unshift('..');
46 }
47 }
48
49 return parts;
50}
51
52// Split a filename into [root, dir, basename, ext], unix version
53// 'root' is just a slash, or nothing.

Callers 2

resolveFunction · 0.85
normalizePathFunction · 0.85

Calls 1

unshiftMethod · 0.80

Tested by

no test coverage detected