fix(aio): support multibyte character in heading (#21414)

PR Close #21414
This commit is contained in:
Suguru Inatomi 2018-01-10 19:52:09 +09:00 committed by Alex Eagle
parent 0de219adcd
commit f15ca6ce50
2 changed files with 12 additions and 1 deletions

View File

@ -136,6 +136,17 @@ describe('ScrollService', () => {
expect(element.scrollIntoView).toHaveBeenCalled(); expect(element.scrollIntoView).toHaveBeenCalled();
expect(window.scrollBy).toHaveBeenCalled(); expect(window.scrollBy).toHaveBeenCalled();
}); });
it('should scroll to the element whose id matches the hash with encoded characters', () => {
const element = new MockElement();
location.hash = '%F0%9F%91%8D'; // 👍
document.getElementById.and.returnValue(element);
scrollService.scroll();
expect(document.getElementById).toHaveBeenCalledWith('👍');
expect(element.scrollIntoView).toHaveBeenCalled();
expect(window.scrollBy).toHaveBeenCalled();
});
}); });
describe('#scrollToElement', () => { describe('#scrollToElement', () => {

View File

@ -83,6 +83,6 @@ export class ScrollService {
* Return the hash fragment from the `PlatformLocation`, minus the leading `#`. * Return the hash fragment from the `PlatformLocation`, minus the leading `#`.
*/ */
private getCurrentHash() { private getCurrentHash() {
return this.location.hash.replace(/^#/, ''); return decodeURIComponent(this.location.hash.replace(/^#/, ''));
} }
} }