MCPcopy Create free account
hub / github.com/TruthHun/BookStack / normalizeArray

Function normalizeArray

static/word2md/mammoth.browser.js:23615–23639  ·  view source on GitHub ↗
(parts, allowAboveRoot)

Source from the content-addressed store, hash-verified

23613// (so also no leading and trailing slashes - it does not distinguish
23614// relative and absolute paths)
23615function normalizeArray(parts, allowAboveRoot) {
23616 // if the path tries to go above the root, `up` ends up > 0
23617 var up = 0;
23618 for (var i = parts.length - 1; i >= 0; i--) {
23619 var last = parts[i];
23620 if (last === '.') {
23621 parts.splice(i, 1);
23622 } else if (last === '..') {
23623 parts.splice(i, 1);
23624 up++;
23625 } else if (up) {
23626 parts.splice(i, 1);
23627 up--;
23628 }
23629 }
23630
23631 // if the path is allowed to go above the root, restore leading ..s
23632 if (allowAboveRoot) {
23633 for (; up--; up) {
23634 parts.unshift('..');
23635 }
23636 }
23637
23638 return parts;
23639}
23640
23641// Split a filename into [root, dir, basename, ext], unix version
23642// 'root' is just a slash, or nothing.

Callers 1

mammoth.browser.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected