diff --git a/packages/url-manager/__tests__/index.test.ts b/packages/url-manager/__tests__/index.test.ts index 37bca98..f47f27f 100644 --- a/packages/url-manager/__tests__/index.test.ts +++ b/packages/url-manager/__tests__/index.test.ts @@ -21,10 +21,6 @@ describe('Basic tests', () => { expect(url.toString()) .toBe('git+ssh://username:password@domain.com:65565/path?test=true#hash') }) - it('should parse and give back the same url', () => { - const url = 'git+ssh://username:password@domain.com:65565/path?test=true&test=false#hash' - expect(new URLManager(url).toString()).toBe(url) - }) it('should be able to add and delete query', () => { const url = new URLManager() diff --git a/packages/url-manager/__tests__/parsing.test.ts b/packages/url-manager/__tests__/parsing.test.ts new file mode 100644 index 0000000..d088edf --- /dev/null +++ b/packages/url-manager/__tests__/parsing.test.ts @@ -0,0 +1,35 @@ +/// + +import URLManager from '../src/URLManager' + +describe('Query Test', () => { + it('should parse basic query', () => { + const url = '?test=true' + expect(new URLManager(url).toString()).toBe(url) + }) + it('should parse query without value', () => { + const url = '?test=' + const url2 = '?test' + expect(new URLManager(url).toString()).toBe(url) + expect(new URLManager(url2).toString()).toBe(url) + }) + it('should ignore query without value while one has a value', () => { + const url = '?test&test=pouet' + expect(new URLManager(url).toString()).toBe('?test=pouet') + }) + it('should parse array query', () => { + const url = '?test=true&test=false&test=pouet' + expect(new URLManager(url).toString()).toBe(url) + }) + it('should parse all at once', () => { + const url = '?test1=true&test2=&test3=true&test3=false' + expect(new URLManager(url).toString()).toBe(url) + }) +}) + +describe('Global Tests', () => { + it('should parse a monstrous url', () => { + const url = 'git+ssh://username:password@domain.com:65565/path?test=true&test=false#hash' + expect(new URLManager(url).toString()).toBe(url) + }) +}) diff --git a/packages/url-manager/package.json b/packages/url-manager/package.json index c82a30e..9c2a498 100644 --- a/packages/url-manager/package.json +++ b/packages/url-manager/package.json @@ -3,6 +3,7 @@ "version": "1.0.2", "description": "Manage URL", "repository": "https://github.com/dzeiocom/libs.git", + "homepage": "https://github.com/dzeiocom/libs/tree/master/packages/url-manager#readme", "author": "Aviortheking", "license": "MIT", "main": "./dist/URLManager.js", diff --git a/packages/url-manager/src/URLManager.ts b/packages/url-manager/src/URLManager.ts index 58ab4a5..d132e5e 100644 --- a/packages/url-manager/src/URLManager.ts +++ b/packages/url-manager/src/URLManager.ts @@ -32,7 +32,13 @@ export default class URLManager { private fromURL(url: string) { const protocolIndex = url.indexOf('://') - const indexOfPath = url.indexOf('/', protocolIndex !== -1 ? protocolIndex + 3 : undefined) + let indexOfPath = url.indexOf('/', protocolIndex !== -1 ? protocolIndex + 3 : undefined) + if (indexOfPath === -1) { + indexOfPath = url.indexOf('?', protocolIndex !== -1 ? protocolIndex + 3 : undefined) + } + if (indexOfPath === -1) { + indexOfPath = url.indexOf('#', protocolIndex !== -1 ? protocolIndex + 3 : undefined) + } const firstPart = url.substr(0, indexOfPath !== -1 ? indexOfPath : undefined) const path = url.substr(firstPart.length)