diff --git a/src/core/event/sidebar.js b/src/core/event/sidebar.js index 0e1f028c1..c142529ef 100644 --- a/src/core/event/sidebar.js +++ b/src/core/event/sidebar.js @@ -83,7 +83,7 @@ export function getAndActive(router, el, isParent, autoTitle) { links .sort((a, b) => b.href.length - a.href.length) .forEach(a => { - const href = a.getAttribute('href'); + const href = decodeURI(a.getAttribute('href')); const node = isParent ? a.parentNode : a; a.title = a.title || a.innerText; diff --git a/test/e2e/sidebar.test.js b/test/e2e/sidebar.test.js new file mode 100644 index 000000000..d289d1cbc --- /dev/null +++ b/test/e2e/sidebar.test.js @@ -0,0 +1,70 @@ +const docsifyInit = require('../helpers/docsify-init'); + +// Suite +// ----------------------------------------------------------------------------- +describe('Sidebar Tests', function() { + // Tests + // --------------------------------------------------------------------------- + test('Active Test', async () => { + const docsifyInitConfig = { + markdown: { + sidebar: ` + - [Test Space](test%20space) + - [Test _](test_foo) + - [Test -](test-foo) + - [Test .](test.foo) + - [Test >](test>foo) + - [Test](test) + `, + }, + routes: { + '/test space.md': ` + # Test Space + `, + '/test_foo.md': ` + # Test _ + `, + '/test-foo.md': ` + # Test - + `, + '/test.foo.md': ` + # Test . + `, + '/test>foo.md': ` + # Test > + `, + '/test.md': ` + # Test page + `, + }, + }; + + await docsifyInit(docsifyInitConfig); + await page.click('a[href="#/test%20space"]'); + await expect(page).toEqualText( + '.sidebar-nav li[class=active]', + 'Test Space' + ); + expect(page.url()).toMatch(/\/test%20space$/); + + await page.click('a[href="#/test_foo"]'); + await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test _'); + expect(page.url()).toMatch(/\/test_foo$/); + + await page.click('a[href="#/test-foo"]'); + await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test -'); + expect(page.url()).toMatch(/\/test-foo$/); + + await page.click('a[href="#/test.foo"]'); + await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test .'); + expect(page.url()).toMatch(/\/test.foo$/); + + await page.click('a[href="#/test>foo"]'); + await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test >'); + expect(page.url()).toMatch(/\/test%3Efoo$/); + + await page.click('a[href="#/test"]'); + await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test'); + expect(page.url()).toMatch(/\/test$/); + }); +});