Commit 45293861 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'dmishunov/hash-retrieval' into 'master'

Optimised the hash retrieval from URL

See merge request gitlab-org/gitlab!65854
parents 8c796cd6 e76fa57d
...@@ -228,11 +228,7 @@ export function removeParams(params, url = window.location.href, skipEncoding = ...@@ -228,11 +228,7 @@ export function removeParams(params, url = window.location.href, skipEncoding =
return `${root}${writableQuery}${writableFragment}`; return `${root}${writableQuery}${writableFragment}`;
} }
export function getLocationHash(url = window.location.href) { export const getLocationHash = (hash = window.location.hash) => hash.split('#')[1];
const hashIndex = url.indexOf('#');
return hashIndex === -1 ? null : url.substring(hashIndex + 1);
}
/** /**
* Returns a boolean indicating whether the URL hash contains the given string value * Returns a boolean indicating whether the URL hash contains the given string value
......
...@@ -371,19 +371,17 @@ describe('URL utility', () => { ...@@ -371,19 +371,17 @@ describe('URL utility', () => {
}); });
describe('doesHashExistInUrl', () => { describe('doesHashExistInUrl', () => {
it('should return true when the given string exists in the URL hash', () => { beforeEach(() => {
setWindowLocation({ setWindowLocation({
href: 'https://gitlab.com/gitlab-org/gitlab-test/issues/1#note_1', hash: 'https://gitlab.com/gitlab-org/gitlab-test/issues/1#note_1',
}); });
});
it('should return true when the given string exists in the URL hash', () => {
expect(urlUtils.doesHashExistInUrl('note_')).toBe(true); expect(urlUtils.doesHashExistInUrl('note_')).toBe(true);
}); });
it('should return false when the given string does not exist in the URL hash', () => { it('should return false when the given string does not exist in the URL hash', () => {
setWindowLocation({
href: 'https://gitlab.com/gitlab-org/gitlab-test/issues/1#note_1',
});
expect(urlUtils.doesHashExistInUrl('doesnotexist')).toBe(false); expect(urlUtils.doesHashExistInUrl('doesnotexist')).toBe(false);
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment