* Resolve a relative URL pathname against a base URL pathname. * * @param {String} relative Pathname of the relative URL. * @param {String} base Pathname of the base URL. * @return {String} Resolved pathname. * @api private
(relative, base)
| 7953 | * @api private |
| 7954 | */ |
| 7955 | function resolve(relative, base) { |
| 7956 | var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/')) |
| 7957 | , i = path.length |
| 7958 | , last = path[i - 1] |
| 7959 | , unshift = false |
| 7960 | , up = 0; |
| 7961 | |
| 7962 | while (i--) { |
| 7963 | if (path[i] === '.') { |
| 7964 | path.splice(i, 1); |
| 7965 | } else if (path[i] === '..') { |
| 7966 | path.splice(i, 1); |
| 7967 | up++; |
| 7968 | } else if (up) { |
| 7969 | if (i === 0) unshift = true; |
| 7970 | path.splice(i, 1); |
| 7971 | up--; |
| 7972 | } |
| 7973 | } |
| 7974 | |
| 7975 | if (unshift) path.unshift(''); |
| 7976 | if (last === '.' || last === '..') path.push(''); |
| 7977 | |
| 7978 | return path.join('/'); |
| 7979 | } |
| 7980 | |
| 7981 | /** |
| 7982 | * The actual URL instance. Instead of returning an object we've opted-in to |
no test coverage detected