Skip to content

Commit 1211fcf

Browse files
committed
fix
1 parent 46ab64b commit 1211fcf

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

web_src/js/features/repo-view-file-tree-sidebar.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {createApp, ref} from 'vue';
22
import {toggleElem} from '../utils/dom.ts';
3+
import {pathEscapeSegments, pathUnescapeSegments} from '../utils/url.ts';
34
import {GET, PUT} from '../modules/fetch.ts';
45
import ViewFileTree from '../components/ViewFileTree.vue';
56

@@ -28,7 +29,7 @@ function childrenLoader(sidebarEl: HTMLElement) {
2829
const fileTree = sidebarEl.querySelector('#view-file-tree');
2930
const apiBaseUrl = fileTree.getAttribute('data-api-base-url');
3031
const refTypeNameSubURL = fileTree.getAttribute('data-current-ref-type-name-sub-url');
31-
const response = await GET(encodeURI(`${apiBaseUrl}/tree/${refTypeNameSubURL}/${path ?? ''}?recursive=${recursive ?? false}`));
32+
const response = await GET(`${apiBaseUrl}/tree/${refTypeNameSubURL}/${pathEscapeSegments(path ?? '')}?recursive=${recursive ?? false}`);
3233
const json = await response.json();
3334
if (json instanceof Array) {
3435
return json.map((i) => ({
@@ -81,7 +82,7 @@ export async function initViewFileTreeSidebar() {
8182

8283
fileTree.classList.remove('is-loading');
8384
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren: childrenLoader(sidebarEl), loadContent: (path: string) => {
84-
window.history.pushState(null, null, encodeURI(`${baseUrl}/src${refString}/${path}`));
85+
window.history.pushState(null, null, `${baseUrl}/src${refString}/${pathEscapeSegments(path)}`);
8586
selectedItem.value = path;
8687
loadContent(sidebarEl);
8788
}});
@@ -94,6 +95,6 @@ export async function initViewFileTreeSidebar() {
9495
}
9596

9697
function getSelectedPath(ref: string) {
97-
const path = decodeURI(new URL(window.location.href).pathname);
98+
const path = pathUnescapeSegments(new URL(window.location.href).pathname);
9899
return path.substring(path.indexOf(ref) + ref.length + 1);
99100
}

web_src/js/utils/url.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export function pathEscapeSegments(s: string): string {
22
return s.split('/').map(encodeURIComponent).join('/');
33
}
44

5+
export function pathUnescapeSegments(s: string): string {
6+
return s.split('/').map(decodeURIComponent).join('/');
7+
}
8+
59
function stripSlash(url: string): string {
610
return url.endsWith('/') ? url.slice(0, -1) : url;
711
}

0 commit comments

Comments
 (0)