Skip to content

Commit

Permalink
chore: rebuild dist
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Gammon <sam@elide.ventures>
  • Loading branch information
sgammon committed Apr 11, 2024
1 parent ebc6f4a commit fac6088
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 497 deletions.
99 changes: 5 additions & 94 deletions dist/axios.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/axios.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/axios.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/axios.min.js.map

Large diffs are not rendered by default.

98 changes: 3 additions & 95 deletions dist/browser/axios.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,83 +2068,9 @@ function trimSlashes(subject, opt_end) {
* @returns {string} The combined URL
*/
function combineURLs(baseURL, relativeURL) {
const combined = relativeURL
? (
(baseURL.charAt(baseURL.length - 1) === '/' ? trimSlashes(baseURL, true) : baseURL)
+ '/'
+ (relativeURL.charAt(0) === '/' ? trimSlashes(relativeURL) : relativeURL)
)
return relativeURL
? baseURL.replace(/\/?\/$/, '') + '/' + trimSlashes(relativeURL.replace(/^\/+/, ''))
: baseURL;

// corner case: if one of the original URLs has multiple slashes which do not reside at the end (for the `baseURL`) or
// at the start (for the `relativeURL`), we sanitize them here. avoidance of regex is deliberate, in order to avoid
// polynomial runtime complexity.
//
// since the `baseURL` and `relativeURL` are guaranteed not to have such artifacts at the end, or beginning,
// respectively (by `trimSlashes`), we only need to do a quick check for the presence of a double-slash. if there is
// none present, we can bail and return the combined URL.
//
// See more: CWE-1333, CWE-400, CWE-730 (https://cwe.mitre.org/index.html)
//
// since Axios only supports a limited set of protocols on each platform, we can safely predict where the protocol
// specifier will be. Then, we can scan the inverse range for any double-slashes. If there is no protocol present (as
// is the case for relative URLs), we can simply scan the string.
//
// the full suite of supported protocol prefixes across all platforms is:
// `['http', 'https', 'file', 'blob', 'url', 'data']`
//
// these are all either three, four, or five characters long (in the lone case of `https`). we use these offsets to
// probe for the protocol string, without iterating, and then proceed as above.
const protocolMinimumOffset = 3 + 1; // 3 character minimum + 1 to arrive at `:`
const protocolMaximumOffset = 5 + 1; // 5 character maximum + 1 to arrive at `:`
const combinedLength = combined.length;
const offset = Math.min(combinedLength, (protocolMaximumOffset + 2));
let sub = combined;

/* eslint-disable */
let protocolPosition = -1;

// if the combined URLs are shorter than the minimum, there is no protocol by definition, and the URLs are both
// relative (and both very small). because we want the offset of the protocol separator, we return `-1` to
// indicate it was not found, or `1` to continue processing (we don't know where it is yet).
if (!(combinedLength < protocolMinimumOffset)) {
// now that we know it's at least as long as the minimum, we can safely slice and check for the protocol tail. the
// length of the string can still be less than the maximum offset + 2, though, so we take the minimum of that and
// the length of the combined string to prevent overflows. at the same time, we assign the smaller search string to
// the subject, so that we don't have to slice it again, and OR-it to the next step.
protocolPosition = ((sub = sub.slice(0, offset)) || sub).includes('://') ?
// we've found the protocol separator; return the start position. since we may have sliced the search space,
// there may or may not be an offset to apply. otherwise, we just return -1 to indicate it was not found (i.e.
// in the case of a relative base URL. since the `indexOf` returns the start of the string, we add `3` to
// include the protocol separator itself.
(sub.indexOf('://') + offset + 3) : -1;
}


// use the above metric to calculate the minimum search space for double-slashes which need to be sanitized.
const doubleSlashSearch = protocolPosition === -1 ? combined : combined.slice(protocolPosition);

// check for double slashes in the target search space. if found, build the return value character by character,
// dropping repeated slashes as we go.
if (doubleSlashSearch.includes('//')) {
let previous = '';
let charIndex = 0;
let charsTotal = doubleSlashSearch.length;
let sanitized = '';

while (charIndex < charsTotal) {
const char = doubleSlashSearch.charAt(charIndex);
if (char === '/' && previous === '/') ; else {
sanitized += char;
}
previous = char;
charIndex++;
}

// finally, if we trimmed the protocol from the search space, we need to combine it again before we return.
return protocolPosition === -1 ? `${combined.slice(0, protocolPosition)}${sanitized}` : sanitized;
}
return combined;
}

/**
Expand Down Expand Up @@ -2556,9 +2482,6 @@ const knownNoBodyResponseStatuses = new Set([
]);

const debugLog = (msg, ...args) => {
{
console.log('[axios:fetch] ', msg, ...args);
}
};

const fetchAssert = (definition) => {
Expand Down Expand Up @@ -2633,7 +2556,6 @@ function processResponseBody(config, response, responseHeaders) {
// the response has a content-length, and therefore a known response size.
hasBody = +(responseHeaders.get(contentLengthHeader) || 0) > 0;
} else {
debugLog('body is chunked');

// the response has a transfer-encoding header indicating a chunked (streamed) response.
hasBody = true;
Expand All @@ -2644,18 +2566,14 @@ function processResponseBody(config, response, responseHeaders) {
// content-type to resolve a value. if all else fails, the data is considered raw data and made available via a
// raw `Blob`.
handler = config.responseType ? selectHandlerFromConfig(config, handlers) : null;
if (config.responseType) {
debugLog('resolved handler from config: ', handler);
}
if (config.responseType) ;

if (hasContentType && handler == null) {
// trim any charset specified
const cleanedContentType = contentType.includes(';') ? contentType.split(';')[0] : contentType;
handler = selectHandlerFromContentType(config, handlers, cleanedContentType);
debugLog('resolved handler from content-type: ', handler);
}
if (handler == null) {
debugLog('no handler found: falling back to `blob`');

// if we get this far, it means there wasn't a handler specified via configuration, and we couldn't easily
// resolve a handler for a text-type via the content-type. we'll have to fall back to a `Blob`.
Expand Down Expand Up @@ -2794,7 +2712,6 @@ function dispatchFetch(config, resolve, reject) {
}

const cleanup = () => {
debugLog('cleanup');
fetchHandle = null;
};

Expand All @@ -2811,7 +2728,6 @@ function dispatchFetch(config, resolve, reject) {
// success handler: translates a `Response` to an axios response
const handleResponse = response => {
if (!fetchHandle) {
debugLog('fetch cancelled; dropping response');
return; // canceled
}
debugLog('response status =', response.status, response.statusText);
Expand All @@ -2821,12 +2737,10 @@ function dispatchFetch(config, resolve, reject) {
const responseHeaders = AxiosHeaders$1.from(
Object.fromEntries(response.headers.entries())
);
debugLog('headers', responseHeaders);

let hasBody = false;
let handler = null;
let eligibleForBody = isResponseEligibleForBody(response);
debugLog('eligible for body =', eligibleForBody);

if (eligibleForBody) {
[hasBody, handler] = processResponseBody(
Expand All @@ -2835,7 +2749,6 @@ function dispatchFetch(config, resolve, reject) {
responseHeaders,
);
}
debugLog('response has body =', hasBody);

const synthesizedResponse = {
status: response.status,
Expand All @@ -2850,7 +2763,6 @@ function dispatchFetch(config, resolve, reject) {
if (hasBody) {
console.warn('axios-fetch: response has a body, but no handler could be resolved.');
}
debugLog('nohandler');
continueChain(synthesizedResponse);
cleanup(); // done
} else {
Expand All @@ -2869,7 +2781,6 @@ function dispatchFetch(config, resolve, reject) {
}, reject);
} catch (err) {
console.error('axios-fetch: error while decoding response data', err);
debugLog('error', err);
reject(err);
} finally {
cleanup();
Expand All @@ -2878,12 +2789,9 @@ function dispatchFetch(config, resolve, reject) {
};

const handleError = err => {
debugLog('error', err);
reject(err);
};

debugLog('fire');

// fire the request
fetchHandle = (config.fetcher || fetcher)(req, Object.assign({}, fetchOptions, {
signal,
Expand Down
2 changes: 1 addition & 1 deletion dist/browser/axios.cjs.map

Large diffs are not rendered by default.

Loading

0 comments on commit fac6088

Please sign in to comment.