Skip to content

Commit dcf5a64

Browse files
enzysy-records
andauthored
fix: sidebar active class and expand don't work as expect when use "space" in markdown filename (#1454)
* fix: decode href in sidebar (#1032) * Create sidebar.test.js Co-authored-by: 沈唁 <[email protected]>
1 parent 76c5e68 commit dcf5a64

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

Diff for: src/core/event/sidebar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function getAndActive(router, el, isParent, autoTitle) {
8383
links
8484
.sort((a, b) => b.href.length - a.href.length)
8585
.forEach(a => {
86-
const href = a.getAttribute('href');
86+
const href = decodeURI(a.getAttribute('href'));
8787
const node = isParent ? a.parentNode : a;
8888

8989
a.title = a.title || a.innerText;

Diff for: test/e2e/sidebar.test.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const docsifyInit = require('../helpers/docsify-init');
2+
3+
// Suite
4+
// -----------------------------------------------------------------------------
5+
describe('Sidebar Tests', function() {
6+
// Tests
7+
// ---------------------------------------------------------------------------
8+
test('Active Test', async () => {
9+
const docsifyInitConfig = {
10+
markdown: {
11+
sidebar: `
12+
- [Test Space](test%20space)
13+
- [Test _](test_foo)
14+
- [Test -](test-foo)
15+
- [Test .](test.foo)
16+
- [Test >](test>foo)
17+
- [Test](test)
18+
`,
19+
},
20+
routes: {
21+
'/test space.md': `
22+
# Test Space
23+
`,
24+
'/test_foo.md': `
25+
# Test _
26+
`,
27+
'/test-foo.md': `
28+
# Test -
29+
`,
30+
'/test.foo.md': `
31+
# Test .
32+
`,
33+
'/test>foo.md': `
34+
# Test >
35+
`,
36+
'/test.md': `
37+
# Test page
38+
`,
39+
},
40+
};
41+
42+
await docsifyInit(docsifyInitConfig);
43+
await page.click('a[href="#/test%20space"]');
44+
await expect(page).toEqualText(
45+
'.sidebar-nav li[class=active]',
46+
'Test Space'
47+
);
48+
expect(page.url()).toMatch(/\/test%20space$/);
49+
50+
await page.click('a[href="#/test_foo"]');
51+
await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test _');
52+
expect(page.url()).toMatch(/\/test_foo$/);
53+
54+
await page.click('a[href="#/test-foo"]');
55+
await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test -');
56+
expect(page.url()).toMatch(/\/test-foo$/);
57+
58+
await page.click('a[href="#/test.foo"]');
59+
await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test .');
60+
expect(page.url()).toMatch(/\/test.foo$/);
61+
62+
await page.click('a[href="#/test>foo"]');
63+
await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test >');
64+
expect(page.url()).toMatch(/\/test%3Efoo$/);
65+
66+
await page.click('a[href="#/test"]');
67+
await expect(page).toEqualText('.sidebar-nav li[class=active]', 'Test');
68+
expect(page.url()).toMatch(/\/test$/);
69+
});
70+
});

0 commit comments

Comments
 (0)