(base, relative)
| 8230 | } |
| 8231 | |
| 8232 | function resolveComponents(base, relative) { |
| 8233 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
| 8234 | var skipNormalization = arguments[3]; |
| 8235 | |
| 8236 | var target = {}; |
| 8237 | if (!skipNormalization) { |
| 8238 | base = parse(serialize(base, options), options); //normalize base components |
| 8239 | relative = parse(serialize(relative, options), options); //normalize relative components |
| 8240 | } |
| 8241 | options = options || {}; |
| 8242 | if (!options.tolerant && relative.scheme) { |
| 8243 | target.scheme = relative.scheme; |
| 8244 | //target.authority = relative.authority; |
| 8245 | target.userinfo = relative.userinfo; |
| 8246 | target.host = relative.host; |
| 8247 | target.port = relative.port; |
| 8248 | target.path = removeDotSegments(relative.path || ""); |
| 8249 | target.query = relative.query; |
| 8250 | } else { |
| 8251 | if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) { |
| 8252 | //target.authority = relative.authority; |
| 8253 | target.userinfo = relative.userinfo; |
| 8254 | target.host = relative.host; |
| 8255 | target.port = relative.port; |
| 8256 | target.path = removeDotSegments(relative.path || ""); |
| 8257 | target.query = relative.query; |
| 8258 | } else { |
| 8259 | if (!relative.path) { |
| 8260 | target.path = base.path; |
| 8261 | if (relative.query !== undefined) { |
| 8262 | target.query = relative.query; |
| 8263 | } else { |
| 8264 | target.query = base.query; |
| 8265 | } |
| 8266 | } else { |
| 8267 | if (relative.path.charAt(0) === "/") { |
| 8268 | target.path = removeDotSegments(relative.path); |
| 8269 | } else { |
| 8270 | if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) { |
| 8271 | target.path = "/" + relative.path; |
| 8272 | } else if (!base.path) { |
| 8273 | target.path = relative.path; |
| 8274 | } else { |
| 8275 | target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path; |
| 8276 | } |
| 8277 | target.path = removeDotSegments(target.path); |
| 8278 | } |
| 8279 | target.query = relative.query; |
| 8280 | } |
| 8281 | //target.authority = base.authority; |
| 8282 | target.userinfo = base.userinfo; |
| 8283 | target.host = base.host; |
| 8284 | target.port = base.port; |
| 8285 | } |
| 8286 | target.scheme = base.scheme; |
| 8287 | } |
| 8288 | target.fragment = relative.fragment; |
| 8289 | return target; |
no test coverage detected