Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sidebar active class and expand don't work as expect when use "space" in markdown filename #1454

Merged
merged 3 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/event/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 70 additions & 0 deletions test/e2e/sidebar.test.js
Original file line number Diff line number Diff line change
@@ -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$/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I get a good warm feeling of Docsify stability improving now!

});
});