Skip to content

Commit d4cb532

Browse files
fix(web): Fix error when navigating to paths with percent symbols (#485)
* fix * changelog
1 parent 2241217 commit d4cb532

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Remove setting `remote.origin.url` for remote git repositories. [#483](https://github.com/sourcebot-dev/sourcebot/pull/483)
12+
- Fix error when navigating to paths with percentage symbols. [#485](https://github.com/sourcebot-dev/sourcebot/pull/485)
1213

1314
### Changed
1415
- Updated NextJS to version 15. [#477](https://github.com/sourcebot-dev/sourcebot/pull/477)

packages/web/src/app/[domain]/browse/[...path]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default async function BrowsePage(props: BrowsePageProps) {
1919
domain
2020
} = params;
2121

22-
const rawPath = decodeURIComponent(_rawPath.join('/'));
22+
const rawPath = _rawPath.join('/');
2323
const { repoName, revisionName, path, pathType } = getBrowseParamsFromPathParam(rawPath);
2424

2525
return (

packages/web/src/app/[domain]/browse/hooks/utils.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ describe('getBrowseParamsFromPathParam', () => {
9898
pathType: 'blob',
9999
});
100100
});
101+
102+
it('should decode paths with percent symbols in path', () => {
103+
const result = getBrowseParamsFromPathParam('github.com/sourcebot-dev/zoekt@HEAD/-/blob/%25hello%25%2Fworld.c');
104+
expect(result).toEqual({
105+
repoName: 'github.com/sourcebot-dev/zoekt',
106+
revisionName: 'HEAD',
107+
path: '%hello%/world.c',
108+
pathType: 'blob',
109+
});
110+
});
111+
112+
it('should decode paths with @ symbol encoded', () => {
113+
const result = getBrowseParamsFromPathParam('github.com/sourcebot-dev/zoekt%40HEAD/-/blob/file.txt');
114+
expect(result).toEqual({
115+
repoName: 'github.com/sourcebot-dev/zoekt',
116+
revisionName: 'HEAD',
117+
path: 'file.txt',
118+
pathType: 'blob',
119+
});
120+
})
101121
});
102122

103123
describe('different revision formats', () => {

packages/web/src/app/[domain]/browse/hooks/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const getBrowseParamsFromPathParam = (pathParam: string) => {
55
throw new Error(`Invalid browse pathname: "${pathParam}" - expected to contain "/-/(tree|blob)/" pattern`);
66
}
77

8-
const repoAndRevisionPart = pathParam.substring(0, sentinelIndex);
8+
const repoAndRevisionPart = decodeURIComponent(pathParam.substring(0, sentinelIndex));
99
const lastAtIndex = repoAndRevisionPart.lastIndexOf('@');
1010

1111
const repoName = lastAtIndex === -1 ? repoAndRevisionPart : repoAndRevisionPart.substring(0, lastAtIndex);

0 commit comments

Comments
 (0)