mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Added unit tests; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+2
-2
@@ -10,6 +10,7 @@ var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||
var transitionalDefaults = require('../defaults/transitional');
|
||||
var AxiosError = require('../core/AxiosError');
|
||||
var CanceledError = require('../cancel/CanceledError');
|
||||
var parseProtocol = require('../helpers/parseProtocol');
|
||||
|
||||
module.exports = function xhrAdapter(config) {
|
||||
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||
@@ -207,8 +208,7 @@ module.exports = function xhrAdapter(config) {
|
||||
requestData = null;
|
||||
}
|
||||
|
||||
var tokens = fullPath.split(':', 2);
|
||||
var protocol = tokens.length > 1 && tokens[0];
|
||||
var protocol = parseProtocol(fullPath);
|
||||
|
||||
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
||||
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function parseProtocol(url) {
|
||||
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
||||
return match && match[1] || '';
|
||||
};
|
||||
Reference in New Issue
Block a user