| 44 | const backslashRegExp = /\\/g; |
| 45 | |
| 46 | const reducePathComponents = (components: readonly string[]) => { |
| 47 | if (!Array.isArray(components) || components.length === 0) { |
| 48 | return []; |
| 49 | } |
| 50 | const reduced = [components[0]]; |
| 51 | for (let i = 1; i < components.length; i++) { |
| 52 | const component = components[i]; |
| 53 | if (!component) continue; |
| 54 | if (component === '.') continue; |
| 55 | if (component === '..') { |
| 56 | if (reduced.length > 1) { |
| 57 | if (reduced[reduced.length - 1] !== '..') { |
| 58 | reduced.pop(); |
| 59 | continue; |
| 60 | } |
| 61 | } else if (reduced[0]) continue; |
| 62 | } |
| 63 | reduced.push(component); |
| 64 | } |
| 65 | return reduced; |
| 66 | }; |
| 67 | |
| 68 | const getRootLength = (path: string) => { |
| 69 | const rootLength = getEncodedRootLength(path); |