diff --git a/__tests__/util/version.js b/__tests__/util/version.js new file mode 100644 index 0000000000..4a93b7fb07 --- /dev/null +++ b/__tests__/util/version.js @@ -0,0 +1,29 @@ +/* @flow */ + +import {explodeHashedUrl} from '../../src/util/version'; + +describe('getDataDir', () => { + test('correctly separates a url with a hash', () => { + const expectedUrl = 'git+ssh://git@github.com:org/proj.git'; + const expectedHash = 'branch'; + const {url, hash} = explodeHashedUrl(`${expectedUrl}#${expectedHash}`); + expect(url).toBe(expectedUrl); + expect(hash).toBe(expectedHash); + }); + + test('returns an empty string as the hash for a url with no hash', () => { + const expectedUrl = 'git+ssh://git@github.com:org/proj.git'; + const expectedHash = ''; + const {url, hash} = explodeHashedUrl(expectedUrl); + expect(url).toBe(expectedUrl); + expect(hash).toBe(expectedHash); + }); + + test('correctly separates a url with a hash in the hash', () => { + const expectedUrl = 'git+ssh://git@github.com:org/proj.git'; + const expectedHash = 'branch#123'; + const {url, hash} = explodeHashedUrl(`${expectedUrl}#${expectedHash}`); + expect(url).toBe(expectedUrl); + expect(hash).toBe(expectedHash); + }); +}); diff --git a/src/util/version.js b/src/util/version.js index a335a5ca50..12e0f43ab3 100644 --- a/src/util/version.js +++ b/src/util/version.js @@ -1,10 +1,10 @@ /* @flow */ export function explodeHashedUrl(url: string): {url: string, hash: string} { - const parts = url.split('#'); + const [server, ...hashes] = url.split('#'); return { - hash: parts[1] || '', - url: parts[0], + hash: hashes.length ? hashes.join('#') : '', + url: server, }; }