Fix broken anchor links when special characters are used

This commit is contained in:
Andrey Krivko 2017-02-03 22:16:26 +06:00
parent 412ab17d3f
commit bcf81d82fa
3 changed files with 20 additions and 0 deletions

View file

@ -69,6 +69,9 @@
var hash = w.gl.utils.getLocationHash();
if (!hash) return;
// This is required to handle non-unicode characters in hash
hash = decodeURIComponent(hash);
var navbar = document.querySelector('.navbar-gitlab');
var subnav = document.querySelector('.layout-nav');
var fixedTabs = document.querySelector('.js-tabs-affix');

View file

@ -0,0 +1,4 @@
---
title: Fix broken anchor links when special characters are used
merge_request: 8961
author: Andrey Krivko

View file

@ -41,6 +41,19 @@ require('~/lib/utils/common_utils');
});
});
describe('gl.utils.handleLocationHash', () => {
beforeEach(() => {
window.history.pushState({}, null, '#definição');
});
it('decodes hash parameter', () => {
spyOn(window.document, 'getElementById').and.callThrough();
gl.utils.handleLocationHash();
expect(window.document.getElementById).toHaveBeenCalledWith('definição');
expect(window.document.getElementById).toHaveBeenCalledWith('user-content-definição');
});
});
describe('gl.utils.getParameterByName', () => {
beforeEach(() => {
window.history.pushState({}, null, '?scope=all&p=2');