Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca8ae50

Browse filesBrowse files
author
Sylvain Brocard
committed
IE compatibility and add unit tests
1 parent 31654f1 commit ca8ae50
Copy full SHA for ca8ae50

3 files changed

+95-3Lines changed: 95 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/core/router/history/base.js‎

Copy file name to clipboardExpand all lines: src/core/router/history/base.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ export class History {
7474
if (local) {
7575
const idIndex = currentRoute.indexOf('?')
7676
path =
77-
(idIndex > 0 ? currentRoute.substr(0, idIndex) : currentRoute) + path
77+
(idIndex > 0 ? currentRoute.substring(0, idIndex) : currentRoute) + path
7878
}
7979

80-
if (this.config.relativePath && !path.startsWith('/')) {
81-
const currentDir = currentRoute.substr(0, currentRoute.lastIndexOf('/') + 1)
80+
if (this.config.relativePath && path.indexOf('/') !== 0) {
81+
const currentDir = currentRoute.substring(0, currentRoute.lastIndexOf('/') + 1)
8282
return cleanPath(resolvePath(currentDir + path))
8383
}
8484
return cleanPath('/' + path)
Collapse file

‎test/unit/base.js‎

Copy file name to clipboard
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-env node, chai, mocha */
2+
require = require('esm')(module/*, options*/)
3+
const {expect} = require('chai')
4+
const {History} = require('../../src/core/router/history/base')
5+
6+
class MockHistory extends History {
7+
parse(path) {
8+
return {path}
9+
}
10+
}
11+
12+
describe('router/history/base', function () {
13+
describe('relativePath true', function () {
14+
var history
15+
16+
beforeEach(function () {
17+
history = new MockHistory({relativePath: true})
18+
})
19+
20+
it('toURL', function () {
21+
// WHEN
22+
const url = history.toURL('guide.md', {}, '/zh-ch/')
23+
24+
// THEN
25+
expect(url).equal('/zh-ch/guide')
26+
})
27+
28+
it('toURL with double dot', function () {
29+
// WHEN
30+
const url = history.toURL('../README.md', {}, '/zh-ch/')
31+
32+
// THEN
33+
expect(url).equal('/README')
34+
})
35+
36+
it('toURL child path', function () {
37+
// WHEN
38+
const url = history.toURL('config/example.md', {}, '/zh-ch/')
39+
40+
// THEN
41+
expect(url).equal('/zh-ch/config/example')
42+
})
43+
44+
it('toURL absolute path', function () {
45+
// WHEN
46+
const url = history.toURL('/README', {}, '/zh-ch/')
47+
48+
// THEN
49+
expect(url).equal('/README')
50+
})
51+
})
52+
53+
it('toURL without relative path', function () {
54+
const history = new MockHistory({relativePath: false})
55+
56+
// WHEN
57+
const url = history.toURL('README', {}, '/zh-ch/')
58+
59+
// THEN
60+
expect(url).equal('/README')
61+
})
62+
})
Collapse file

‎test/unit/util.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-env node, chai, mocha */
2+
require = require('esm')(module/*, options*/)
3+
const {expect} = require('chai')
4+
const {resolvePath} = require('../../src/core/router/util')
5+
6+
describe('router/util', function () {
7+
it('resolvePath', async function () {
8+
// WHEN
9+
const result = resolvePath('hello.md')
10+
11+
// THEN
12+
expect(result).equal('/hello.md')
13+
})
14+
15+
it('resolvePath with dot', async function () {
16+
// WHEN
17+
const result = resolvePath('./hello.md')
18+
19+
// THEN
20+
expect(result).equal('/hello.md')
21+
})
22+
23+
it('resolvePath with two dots', async function () {
24+
// WHEN
25+
const result = resolvePath('test/../hello.md')
26+
27+
// THEN
28+
expect(result).equal('/hello.md')
29+
})
30+
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.