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