Skip to content

Commit f2713b4

Browse files
committed
Avoid forward slashes to be encoded
1 parent 901fef5 commit f2713b4

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/adapters/adapter.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Adapter {
5858

5959
item.id = NODE_PREFIX + path
6060
item.text = name
61-
item.icon = type // use `type` as class name for tree node
61+
item.icon = type // uses `type` as class name for tree node
6262

6363
if (node) {
6464
folders[''].push(item)
@@ -67,16 +67,16 @@ class Adapter {
6767
folders[path.substring(0, index)].push(item)
6868
}
6969

70-
if (type === 'tree') {
71-
if (node) item.children = true
72-
else folders[item.path] = item.children = []
73-
item.a_attr = {
74-
href: `/${repo.username}/${repo.reponame}/${type}/${repo.branch}/${encodeURIComponent(path)}`
70+
if (type === 'tree' || type === 'blob') {
71+
if (type === 'tree') {
72+
if (node) item.children = true
73+
else folders[item.path] = item.children = []
7574
}
76-
}
77-
else if (type === 'blob') {
75+
76+
// encodes but retains the slashes, see #274
77+
const encodedPath = path.split('/').map(encodeURIComponent).join('/')
7878
item.a_attr = {
79-
href: `/${repo.username}/${repo.reponame}/${type}/${repo.branch}/${encodeURIComponent(path)}`
79+
href: `/${repo.username}/${repo.reponame}/${type}/${repo.branch}/${encodedPath}`
8080
}
8181
}
8282
else if (type === 'commit') {

src/view.tree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class TreeView {
101101
let $target = $(event.target)
102102
let download = false
103103

104+
// handle middle click
105+
if (event.which === 2) return
106+
104107
// handle icon click, fix #122
105108
if ($target.is('i.jstree-icon')) {
106109
$target = $target.parent()
@@ -109,9 +112,6 @@ class TreeView {
109112

110113
if (!$target.is('a.jstree-anchor')) return
111114

112-
// handle middle click
113-
if (event.which === 2) return
114-
115115
// refocus after complete so that keyboard navigation works, fix #158
116116
const refocusAfterCompletion = () => {
117117
$(document).one('pjax:success page:load', () => {

0 commit comments

Comments
 (0)