mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-20 22:27:24 -04:00
Trim URL before adding missing proto (Closes #1205)
This commit is contained in:
@@ -11,6 +11,11 @@ describe('setDefaultProtocol()', () => {
|
||||
expect(url).toBe('http://google.com');
|
||||
});
|
||||
|
||||
it('correctly sets protocol for padded domain', () => {
|
||||
const url = setDefaultProtocol(' google.com ');
|
||||
expect(url).toBe('http://google.com');
|
||||
});
|
||||
|
||||
it('does not set for valid url', () => {
|
||||
const url = setDefaultProtocol('https://google.com');
|
||||
expect(url).toBe('https://google.com');
|
||||
|
||||
@@ -5,17 +5,18 @@
|
||||
* @returns {string}
|
||||
*/
|
||||
module.exports.setDefaultProtocol = function(url, defaultProto) {
|
||||
const trimmedUrl = url.trim();
|
||||
defaultProto = defaultProto || 'http:';
|
||||
|
||||
// If no url, don't bother returning anything
|
||||
if (!url) {
|
||||
if (!trimmedUrl) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Default the proto if it doesn't exist
|
||||
if (url.indexOf('://') === -1) {
|
||||
url = `${defaultProto}//${url}`;
|
||||
if (trimmedUrl.indexOf('://') === -1) {
|
||||
return `${defaultProto}//${trimmedUrl}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
return trimmedUrl;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user