(parts, allowAboveRoot)
| 216 | // (so also no leading and trailing slashes - it does not distinguish |
| 217 | // relative and absolute paths) |
| 218 | function normalizeArray(parts, allowAboveRoot) { |
| 219 | // if the path tries to go above the root, `up` ends up > 0 |
| 220 | var up = 0; |
| 221 | for (var i = parts.length; i >= 0; i--) { |
| 222 | var last = parts[i]; |
| 223 | if (last == '.') { |
| 224 | parts.splice(i, 1); |
| 225 | } else if (last === '..') { |
| 226 | parts.splice(i, 1); |
| 227 | up++; |
| 228 | } else if (up) { |
| 229 | parts.splice(i, 1); |
| 230 | up--; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // if the path is allowed to go above the root, restore leading ..s |
| 235 | if (allowAboveRoot) { |
| 236 | for (; up--; up) { |
| 237 | parts.unshift('..'); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | return parts; |
| 242 | } |
| 243 | |
| 244 | // Regex to split a filename into [*, dir, basename, ext] |
| 245 | // posix version |
no outgoing calls
no test coverage detected
searching dependent graphs…