* 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)
| 8089 | * @api private |
| 8090 | */ |
| 8091 | function resolve(relative, base) { |
| 8092 | var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/')) |
| 8093 | , i = path.length |
| 8094 | , last = path[i - 1] |
| 8095 | , unshift = false |
| 8096 | , up = 0; |
| 8097 | |
| 8098 | while (i--) { |
| 8099 | if (path[i] === '.') { |
| 8100 | path.splice(i, 1); |
| 8101 | } else if (path[i] === '..') { |
| 8102 | path.splice(i, 1); |
| 8103 | up++; |
| 8104 | } else if (up) { |
| 8105 | if (i === 0) unshift = true; |
| 8106 | path.splice(i, 1); |
| 8107 | up--; |
| 8108 | } |
| 8109 | } |
| 8110 | |
| 8111 | if (unshift) path.unshift(''); |
| 8112 | if (last === '.' || last === '..') path.push(''); |
| 8113 | |
| 8114 | return path.join('/'); |
| 8115 | } |
| 8116 | |
| 8117 | /** |
| 8118 | * The actual URL instance. Instead of returning an object we've opted-in to |
no test coverage detected