diff --git a/src/utils.ts b/src/utils.ts index ed0307a..d104a12 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -266,7 +266,7 @@ export const formatHost = (host: string): string => { if (host.startsWith(':')) { // if host starts with ':', prepend the default hostname host = `http://127.0.0.1${host}` - isExplicitProtocol = false + isExplicitProtocol = true } if (!isExplicitProtocol) { diff --git a/test/index.spec.ts b/test/index.spec.ts index d6756fd..3376ba3 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -13,6 +13,10 @@ describe('formatHost Function Tests', () => { expect(formatHost('1.2.3.4:56789')).toBe('http://1.2.3.4:56789') }) + it('should parse with only a port', () => { + expect(formatHost(':56789')).toBe('http://127.0.0.1:56789') + }) + it('should parse HTTP URL', () => { expect(formatHost('http://1.2.3.4')).toBe('http://1.2.3.4:80') }) @@ -52,4 +56,8 @@ describe('formatHost Function Tests', () => { it('should handle trailing slash in domain with port', () => { expect(formatHost('example.com:56789/')).toBe('http://example.com:56789') }) + + it('should handle traling slash with only a port', () => { + expect(formatHost(':56789/')).toBe('http://127.0.0.1:56789') + }) })