Absolute, according to whom
The code below is the file exactly as it stood in axios/axios. The defect was introduced on 2015-11-22, reviewed, merged, and fixed on 2024-08-13 in commit 07a661a2 — after 3187 days in the tree.
The commit was written by a human contributor to axios/axios, not by an agent. The ticket and the description on the next two panels are ours — a reconstruction of the case the original change made, so you meet it the way its reviewer did. The code, the defect and the dates are untouched.
Let a per-request URL override the configured baseURL
Callers configure a `baseURL` once on the client. A few call sites need to hit a different host for a single request — an upload endpoint on a CDN, a health check on an internal service — and today the base is always prepended.
Add a helper that decides whether a requested URL is already absolute. If it is, use it as given; otherwise join it to the base. Follow RFC 3986 for what counts as a scheme.
Added `isAbsoluteURL` and wired it into `buildFullPath`, so the base is only applied to relative URLs.
The regex follows RFC 3986 §3.1: a scheme is a letter followed by letters, digits, `+`, `-` or `.`, terminated by `:`. I made the scheme group optional so protocol-relative URLs — `//cdn.example.com/asset.png`, what the URL spec calls a network-path reference — are treated as absolute too. They are: a protocol-relative URL resolves against the current scheme rather than against our base path, so prepending `baseURL` to one would produce a URL pointing nowhere.
Case-insensitive, because RFC 3986 says schemes are case-insensitive. `combineURLs` is unchanged.
Our reconstruction of the argument the real change made, not a quotation of it. Fluent, specific, and not evidence of anything — which is the point.
'use strict'; /** * Determines whether the specified URL is absolute * * @param {string} url The URL to test * * @returns {boolean} True if the specified URL is absolute, otherwise false */export default function isAbsoluteURL(url) { // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL). // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed // by any combination of letters, digits, plus, period, or hyphen. return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);}'use strict'; /** * Creates a new URL by combining the specified URLs * * @param {string} baseURL The base URL * @param {string} relativeURL The relative URL * * @returns {string} The combined URL */export default function combineURLs(baseURL, relativeURL) { return relativeURL ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;}'use strict'; import isAbsoluteURL from '../helpers/isAbsoluteURL.js';import combineURLs from '../helpers/combineURLs.js'; /** * Creates a new URL by combining the baseURL with the requestedURL, * only when the requestedURL is not already an absolute URL. * If the requestURL is absolute, this function returns the requestedURL untouched. * * @param {string} baseURL The base URL * @param {string} requestedURL Absolute or relative URL to combine * * @returns {string} The combined full path */export default function buildFullPath(baseURL, requestedURL) { if (baseURL && !isAbsoluteURL(requestedURL)) { return combineURLs(baseURL, requestedURL); } return requestedURL;}